mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Improves NewAuthenticateForTest()
This commit is contained in:
parent
9e01b54307
commit
6d307a6aa6
1 changed files with 13 additions and 6 deletions
|
@ -203,23 +203,30 @@ func NewAuthenticateForTest(router *gin.Engine, url string,
|
|||
http.StatusOK, w.Code)
|
||||
}
|
||||
|
||||
var body_data map[string]interface{}
|
||||
|
||||
// Get the response
|
||||
var body_data map[string]interface{}
|
||||
err = json.Unmarshal([]byte(w.Body.String()), &body_data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Check the response
|
||||
success := body_data["success"].(bool)
|
||||
success, ok := body_data["success"].(bool)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Type asssertion of response[\"success\"] failed")
|
||||
}
|
||||
if !success {
|
||||
fmt.Println("Authentication not successful: ", body_data["message"])
|
||||
return "", fmt.Errorf("Authentication unsuccessful!")
|
||||
return "", fmt.Errorf("Authentication failed!", body_data["message"])
|
||||
}
|
||||
|
||||
// Extract the token
|
||||
token, ok := body_data["token"].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Type assertion of response[\"token\"] failed")
|
||||
}
|
||||
|
||||
// Return the token and nil error
|
||||
return body_data["token"].(string), nil
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func AuthenticateForTest(t *testing.T, router *gin.Engine, url string, method string, body []byte, expected_code int) string {
|
||||
|
|
Loading…
Add table
Reference in a new issue