我有一个文件包含一些应该在Go 1.5+上运行的测试.
我能够使用Go运行版runtime.Version()
并进行各种比较.
但是,测试文件导入golang.org/x/net/http2
.该http2
包需要request.Cancel()
从net/http
,但仅适用于进入1.5+.
这导致我的CI环境中的这些错误导致构建失败:
../../../golang.org/x/net/http2/transport.go:214: req.Cancel undefined (type *http.Request has no field or method Cancel)
../../../golang.org/x/net/http2/transport.go:218: req.Cancel undefined (type *http.Request has no field or method Cancel)
../../../golang.org/x/net/http2/transport.go:777: req.Cancel undefined (type *http.Request has no field or method Cancel)
Run Code Online (Sandbox Code Playgroud)
我尝试添加// +build go1.5
到文件的顶部,但它不起作用.
无论如何我可以限制单元测试文件,以便它只在Go 1.5+系统上构建和测试?