我正在尝试进行一些go
测试,错误如下:
▶ go test -timeout 100000000s -cover -race
# github.com/tj/assert
../../../../../go/pkg/mod/github.com/tj/assert@v0.0.1/require.go:191:29: too many arguments in call to assert.HTTPBodyContains
have (TestingT, http.HandlerFunc, string, string, url.Values, io.Reader, interface {}, []interface {}...)
want (assert.TestingT, http.HandlerFunc, string, string, url.Values, interface {}, ...interface {})
../../../../../go/pkg/mod/github.com/tj/assert@v0.0.1/require.go:203:32: too many arguments in call to assert.HTTPBodyNotContains
have (TestingT, http.HandlerFunc, string, string, url.Values, io.Reader, interface {}, []interface {}...)
want (assert.TestingT, http.HandlerFunc, string, string, url.Values, interface {}, ...interface {})
FAIL github.com/myrepo/myproject/lib/somelib [build failed]
在我的go.mod
▶ cat go.mod | grep -i tj
github.com/tj/assert v0.0.1
是什么原因导致上述错误?
答案 0 :(得分:3)
github.com/tj/assert@v0.0.1
的第191行是:
if !assert.HTTPBodyContains(t, handler, method, url, values, body, str, msgAndArgs...)
由于导入assert "github.com/stretchr/testify/assert"
,因此引用了stretchr testify package,该定义HTTPBodyContains
为
HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{})
因此您得到的错误原因似乎很清楚;错误状态:
have (TestingT, http.HandlerFunc, string, string, url.Values, io.Reader, interface {}, []interface {}...)
want (assert.TestingT, http.HandlerFunc, string, string, url.Values, interface {}, ...interface {})
我怀疑真正的问题是:
assert "github.com/stretchr/testify/assert"
并在该程序包中调用函数。要解决此问题,请从函数名称之前删除assert.
。assert@v0.0.1
,但具有更高版本。使用go get
检索最新版本(请参阅upgrading dependencies上的文档)。