请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

HTTP Version Not Supported

老师好,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

正在回答 回答被采纳积分+3

1回答

ccmouse 2020-05-02 16:35:36

这个是ErrorWrapper或是he/heUE两个函数逻辑有错。可以用调试器单步跟踪的方法查找错误。

还有是通过505, HTTP Version Not Supported,StatusHTTPVersionNotSupported 等特征字符串去搜索你自己的代码,看哪里有返回这些。


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信