【发布时间】:2021-11-06 00:09:09
【问题描述】:
我想编写验证正确文档以到达第三方服务器的Oauth2.0的测试,我应该如何完成伪代码?
import (
"net/http"
"net/http/httptest"
}
func testAuthServer(t *testing.T) {
form := url.Values{}
form.Set(...)
r := httptest.NewRequest(http.MethodPost, authUrl, strings.NewReader(form.Encode()))
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
w := httptest.NewRecorder()
// test the auth server
if w.Code != http.StatusOK {
...
}
}
【问题讨论】:
-
只是为了确定:您可以断言发送到服务器的正文是预期的吗?你不关心服务器的URL?
-
抱歉,authUrl 不是本地测试服务器,是现有的第三方资源。
-
在这种情况下,您可能可以使用像 gock 这样的工具。我更新了答案。
标签: go go-testing