Skipping Tests Based on Go Version in Test Files
You have a test file that requires Go 1.5 but imports a package (golang.org/x/net/http2) that requires request.Cancel() from net/http, which is only available in Go 1.5 . To resolve this issue, use build constraints to limit the compilation and execution of the test file to Go 1.5 systems.
Build constraints are directives placed near the top of a file that specify the conditions under which that file should be built. In your case, you can add the following build constraint to the top of your test file:
// +build go1.5
This constraint tells the compiler to only include the file in the build if Go 1.5 or later is being used.
However, note that the error messages you provided refer to the http2 package, which was added in Go 1.6. Therefore, you should use the following build constraint to restrict compilation to Go 1.6 and above:
// +build go1.6
Build constraints must appear near the top of the file, preceded only by blank lines and line comments. They must also be followed by a blank line to distinguish them from package documentation.
The above is the detailed content of How Can I Skip Go Tests Based on the Go Version?. For more information, please follow other related articles on the PHP Chinese website!