cli/command/cli_options_test.go:29:2: os.Setenv() can be replaced by `t.Setenv()` in TestWithContentTrustFromEnv (tenv)
os.Setenv(envvar, "true")
^
cli/command/cli_options_test.go:31:2: os.Setenv() can be replaced by `t.Setenv()` in TestWithContentTrustFromEnv (tenv)
os.Setenv(envvar, "false")
^
cli/command/cli_options_test.go:33:2: os.Setenv() can be replaced by `t.Setenv()` in TestWithContentTrustFromEnv (tenv)
os.Setenv(envvar, "invalid")
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
28 lines
658 B
Go
28 lines
658 B
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func contentTrustEnabled(t *testing.T) bool {
|
|
var cli DockerCli
|
|
assert.NilError(t, WithContentTrustFromEnv()(&cli))
|
|
return cli.contentTrust
|
|
}
|
|
|
|
// NB: Do not t.Parallel() this test -- it messes with the process environment.
|
|
func TestWithContentTrustFromEnv(t *testing.T) {
|
|
const envvar = "DOCKER_CONTENT_TRUST"
|
|
t.Setenv(envvar, "true")
|
|
assert.Check(t, contentTrustEnabled(t))
|
|
t.Setenv(envvar, "false")
|
|
assert.Check(t, !contentTrustEnabled(t))
|
|
t.Setenv(envvar, "invalid")
|
|
assert.Check(t, contentTrustEnabled(t))
|
|
os.Unsetenv(envvar)
|
|
assert.Check(t, !contentTrustEnabled(t))
|
|
}
|