老师好,httptest的时候报错,请问下是什么原因,这个是源码
func TestErrorWrapper(t *testing.T) {
tests := []struct {
ahe AppHandlerErr
code int
message string
}{
{he, http.StatusInternalServerError, ""},
{heUE, http.StatusBadRequest, "自定义"},
}
for _, testObj := range tests {
appHandler := ErrorWrapper(testObj.ahe)
response := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodGet, "http://www.imooc.com", nil)
appHandler(response, request)
buffer, _ := ioutil.ReadAll(response.Body)
code := response.Code
var body = strings.Trim(string(buffer), "\n")
if testObj.code != code || body != testObj.message {
t.Errorf("get(%d, message:%s),not %d,%s", code, body, testObj.code, testObj.message)
}
}
}
=== RUN TestErrorWrapper
2020/05/01 21:28:48 unknow pro 123
TestErrorWrapper: web_test.go:42: get(505, message:HTTP Version Not Supported),not 500,
2020/05/01 21:28:48 unknow pro 自定义
TestErrorWrapper: web_test.go:42: get(505, message:HTTP Version Not Supported),not 400,自定义
— FAIL: TestErrorWrapper (0.01s)
FAIL
Process finished with exit code 1