From ce82267a111f9e5711bfbb03acf954188dcd38fb Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 21 Sep 2021 11:21:13 +0200 Subject: [PATCH] refactor: drop unused Unsetenv from testutil Signed-off-by: Mark Sagi-Kazar --- internal/testutil/env.go | 33 --------------------------------- internal/testutil/env_go1_16.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 33 deletions(-) delete mode 100644 internal/testutil/env.go diff --git a/internal/testutil/env.go b/internal/testutil/env.go deleted file mode 100644 index f2427f5..0000000 --- a/internal/testutil/env.go +++ /dev/null @@ -1,33 +0,0 @@ -package testutil - -import ( - "os" - "testing" -) - -// Based on https://github.com/frankban/quicktest/blob/577841610793d24f99e31cc2c0ef3a541fefd7c7/patch.go#L34-L64 -// Licensed under the MIT license -// Copyright (c) 2017 Canonical Ltd. - -// Unsetenv unsets an environment variable for the duration of a test. -func Unsetenv(t *testing.T, name string) { - setenv(t, name, "", false) -} - -// setenv sets or unsets an environment variable to a temporary value for the -// duration of the test -func setenv(t *testing.T, name, val string, valOK bool) { - oldVal, oldOK := os.LookupEnv(name) - if valOK { - os.Setenv(name, val) - } else { - os.Unsetenv(name) - } - t.Cleanup(func() { - if oldOK { - os.Setenv(name, oldVal) - } else { - os.Unsetenv(name) - } - }) -} diff --git a/internal/testutil/env_go1_16.go b/internal/testutil/env_go1_16.go index 5c1f7f9..8769a44 100644 --- a/internal/testutil/env_go1_16.go +++ b/internal/testutil/env_go1_16.go @@ -20,3 +20,21 @@ import ( func Setenv(t *testing.T, name, val string) { setenv(t, name, val, true) } + +// setenv sets or unsets an environment variable to a temporary value for the +// duration of the test +func setenv(t *testing.T, name, val string, valOK bool) { + oldVal, oldOK := os.LookupEnv(name) + if valOK { + os.Setenv(name, val) + } else { + os.Unsetenv(name) + } + t.Cleanup(func() { + if oldOK { + os.Setenv(name, oldVal) + } else { + os.Unsetenv(name) + } + }) +}