Set Content-Type in test and handle error earlier
This commit is contained in:
parent
1c003486ca
commit
08fbacc7e6
@ -39,13 +39,19 @@ func TestRegisterUser(t *testing.T) {
|
|||||||
http.MethodPost,
|
http.MethodPost,
|
||||||
"/api/v1/user/register",
|
"/api/v1/user/register",
|
||||||
strings.NewReader(`{"password":"pass","email":"info@example.com","name":"Test"}`))
|
strings.NewReader(`{"password":"pass","email":"info@example.com","name":"Test"}`))
|
||||||
|
request.Header.Set("Content-Type", "application/json")
|
||||||
context := engine.NewContext(request, recorder)
|
context := engine.NewContext(request, recorder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error creating request: %s", err)
|
t.Errorf("error creating request: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h.registerPost(context)
|
err = h.registerPost(context)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
t.Error("Error registering")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
t.Errorf("handler returned wrong status code: got %v want %v", recorder.Code, http.StatusOK)
|
t.Errorf("handler returned wrong status code: got %v want %v", recorder.Code, http.StatusOK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user