for _, tc := range testCases {
t.Run(tc.user, func(t *testing.T) {
reqBody, _ := json.Marshal(map[string]string{
"user": tc.user,
"password": tc.password,
})
rec := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/auth", bytes.NewBuffer(reqBody))
controllers.Auth(rec, req)
resp := rec.Result()
body, _ := ioutil.ReadAll(resp.Body)
status, _, _, _ := jsonparser.Get(body, "status")
assert.Equal(t, tc.want, string(status))
})
}
}
I wrote a test that doesn't work gives out a lot of panics help me figure out why Here on this line crashes
controllers.Auth(rec, req)
This is the output panic:
--- FAIL: TestHandleAuth (0.00s)
--- FAIL: TestHandleAuth/midaef (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference
[recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x1b0 pc=0x74a1b1]
This is output stack trace:
packages/tests.TestHandleAuth.func1(0xc00011f320)
c:/repos/NLBook/user-microservice/tests/auth_test.go:40 +0x2a1
testing.tRunner(0xc00011f320, 0xc00017a020)
Aucun commentaire:
Enregistrer un commentaire