2019-01-28 12:38:33 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2019-01-28 12:38:33 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func contentTrustEnabled(t *testing.T) bool {
|
2023-11-20 05:10:29 -05:00
|
|
|
t.Helper()
|
2019-01-28 12:38:33 -05:00
|
|
|
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) {
|
2022-09-02 17:04:20 -04:00
|
|
|
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))
|
2019-01-28 12:38:33 -05:00
|
|
|
os.Unsetenv(envvar)
|
2022-09-02 17:04:20 -04:00
|
|
|
assert.Check(t, !contentTrustEnabled(t))
|
2019-01-28 12:38:33 -05:00
|
|
|
}
|