相关疑难解决方法(0)

如果测试文件在1.4及以下版本的系统上运行,如何跳过测试文件?

我有一个文件包含一些应该在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+系统上构建和测试?

unit-testing go

4
推荐指数
1
解决办法
357
查看次数

标签 统计

go ×1

unit-testing ×1