From 8dc18ce7d070fc6cc5a918b1cc7c3385dfca7241 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 2 Sep 2022 23:04:20 +0200 Subject: [PATCH] linting: os.Setenv() can be replaced by `t.Setenv()` (tenv) 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 (cherry picked from commit cef858170d1193661d95ccf61c869ca8d0e18b43) Signed-off-by: Cory Snider --- cli/command/cli_options_test.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/cli/command/cli_options_test.go b/cli/command/cli_options_test.go index 0085023913..4ed0f8f90e 100644 --- a/cli/command/cli_options_test.go +++ b/cli/command/cli_options_test.go @@ -15,23 +15,13 @@ func contentTrustEnabled(t *testing.T) bool { // NB: Do not t.Parallel() this test -- it messes with the process environment. func TestWithContentTrustFromEnv(t *testing.T) { - envvar := "DOCKER_CONTENT_TRUST" - if orig, ok := os.LookupEnv(envvar); ok { - defer func() { - os.Setenv(envvar, orig) - }() - } else { - defer func() { - os.Unsetenv(envvar) - }() - } - - os.Setenv(envvar, "true") - assert.Assert(t, contentTrustEnabled(t)) - os.Setenv(envvar, "false") - assert.Assert(t, !contentTrustEnabled(t)) - os.Setenv(envvar, "invalid") - assert.Assert(t, contentTrustEnabled(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.Assert(t, !contentTrustEnabled(t)) + assert.Check(t, !contentTrustEnabled(t)) }