Open cardil opened 2 years ago
I think the following fragment is responsible for this discrepancy:
Arguably the test is both fragile and wrong, it tests for an unset value (ie use the default) when it actually needs the specific value of off.
Change https://go.dev/cl/424999 mentions this issue: cmd/test2json: use original environment to mirror go test
The point is that the test2json
uses effective env - same as go env
, but go test
actually uses the original env: https://github.com/golang/go/blob/bf4e35b658e61c29112c456f47615c16345c3518/src/cmd/go/internal/test/test.go#L1358
The PR #54554 align this to be the same.
go tool test2json
is not a supported way to run tests. If you want precise control over the process's environment, use go tool -n test2json
to obtain the path to the tool, and then run it with whatever environment you need for it.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
make repro
What did you expect to see?
I expect to see the test pass regardless if executed via:
or
What did you see instead?
The process fails with the following output:
Additional context
I stumbled on this problem while running tests via the Goland IDE. The Goland IDE uses the pair of commands to execute tests:
We are executing google/ko in our tests to built test OCI images. KO sets the
CGO_ENABLED=0
by default because the default base image is distroless, which doesn't contain any system libraries.When I execute tests from Goland IDE, I have effectively
CGO_ENABLED=1
when the test starts. This overrides the KO default value, and the produced image is invalid. The faulty image contains dynamic binary, which can't run on distroless.When the tests are executed with
go test
directly, all is well.I think running tests via
go tool test2json -t
shouldn't change the execution environment for the test.See also: https://github.com/knative-sandbox/control-protocol/pull/204