diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-06 10:05:17 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-07 07:50:27 +0300 |
commit | bf214c40cdea0f390e885298d7cf74056c68c6f2 (patch) | |
tree | d43a4be74eb9f28a1e530737248d3392f6a6c9f6 | |
parent | e34689502c46f6693006e259ed94e96ec3fa09b4 (diff) |
global: Rewrite callers of `testhelper.ModifyEnvironment()`
Rewrite callers of `testhelper.ModifyEnviroment()`, which is about to be
removed in favor of either `t.Setenv()` or `testhelper.Unsetenv()`.
-rw-r--r-- | .golangci.yml | 5 | ||||
-rw-r--r-- | client/dial_test.go | 6 | ||||
-rw-r--r-- | cmd/gitaly-ssh/auth_test.go | 3 | ||||
-rw-r--r-- | internal/backup/backup_test.go | 3 | ||||
-rw-r--r-- | internal/command/command_test.go | 4 | ||||
-rw-r--r-- | internal/git/command_factory_test.go | 12 | ||||
-rw-r--r-- | internal/git/execution_environment_test.go | 20 | ||||
-rw-r--r-- | internal/gitaly/server/server_factory_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/repository/create_fork_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/checks_test.go | 2 | ||||
-rw-r--r-- | internal/supervisor/supervisor_test.go | 2 |
11 files changed, 31 insertions, 31 deletions
diff --git a/.golangci.yml b/.golangci.yml index db6ed2d7e..31c722364 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,9 +59,8 @@ linters-settings: - ^context.Background$ - ^context.TODO$ # Tests should not set the bare environment functions, but instead use - # `testhelper.ModifyEnvironment()`. This function has sanity checks to - # verify we don't use `t.Parallel()` when setting envvars by using the - # `t.Setenv()` helper. + # `t.Setenv()` or `testhelper.Unsetenv()`. These functions have sanity + # checks to verify we don't use `t.Parallel()` when setting envvars. - ^os.Setenv$ - ^os.Unsetenv$ stylecheck: diff --git a/client/dial_test.go b/client/dial_test.go index f958fc13c..f488a3ede 100644 --- a/client/dial_test.go +++ b/client/dial_test.go @@ -128,8 +128,9 @@ func TestDial(t *testing.T) { } if tt.envSSLCertFile != "" { - testhelper.ModifyEnvironment(t, gitalyx509.SSLCertFile, tt.envSSLCertFile) + t.Setenv(gitalyx509.SSLCertFile, tt.envSSLCertFile) } + ctx := testhelper.Context(t) conn, err := Dial(tt.rawAddress, tt.dialOpts) @@ -216,8 +217,9 @@ func TestDialSidechannel(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if tt.envSSLCertFile != "" { - testhelper.ModifyEnvironment(t, gitalyx509.SSLCertFile, tt.envSSLCertFile) + t.Setenv(gitalyx509.SSLCertFile, tt.envSSLCertFile) } + ctx := testhelper.Context(t) conn, err := DialSidechannel(ctx, tt.rawAddress, registry, tt.dialOpts) diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go index a8cf5a6a3..007522314 100644 --- a/cmd/gitaly-ssh/auth_test.go +++ b/cmd/gitaly-ssh/auth_test.go @@ -96,8 +96,7 @@ func TestConnectivity(t *testing.T) { name: "tls", addr: func(t *testing.T, cfg config.Cfg) (string, string) { certFile, keyFile := testhelper.GenerateCerts(t) - - testhelper.ModifyEnvironment(t, x509.SSLCertFile, certFile) + t.Setenv(x509.SSLCertFile, certFile) cfg.TLSListenAddr = "localhost:0" cfg.TLS = config.TLS{ diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index 3bcaad4c8..0ae30291f 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -602,8 +602,9 @@ func TestResolveSink(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { for k, v := range tc.envs { - testhelper.ModifyEnvironment(t, k, v) + t.Setenv(k, v) } + sink, err := ResolveSink(ctx, tc.path) if tc.errMsg != "" { require.EqualError(t, err, tc.errMsg) diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 4e2f80248..98569183f 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -116,7 +116,7 @@ func TestNew_exportedEnvironment(t *testing.T) { t.Skip("System Integrity Protection prevents using dynamic linker (dyld) environment variables on macOS. https://apple.co/2XDH4iC") } - testhelper.ModifyEnvironment(t, tc.key, tc.value) + t.Setenv(tc.key, tc.value) var buf bytes.Buffer cmd, err := New(ctx, exec.Command("/usr/bin/env"), WithStdout(&buf)) @@ -133,7 +133,7 @@ func TestNew_unexportedEnv(t *testing.T) { ctx := testhelper.Context(t) unexportedEnvKey, unexportedEnvVal := "GITALY_UNEXPORTED_ENV", "foobar" - testhelper.ModifyEnvironment(t, unexportedEnvKey, unexportedEnvVal) + t.Setenv(unexportedEnvKey, unexportedEnvVal) var buf bytes.Buffer cmd, err := New(ctx, exec.Command("/usr/bin/env"), WithStdout(&buf)) diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index ede45c745..5868e539c 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -33,7 +33,7 @@ func TestGitCommandProxy(t *testing.T) { })) defer ts.Close() - testhelper.ModifyEnvironment(t, "http_proxy", ts.URL) + t.Setenv("http_proxy", ts.URL) ctx := testhelper.Context(t) @@ -146,8 +146,8 @@ func TestExecCommandFactory_NewWithDir(t *testing.T) { } func TestCommandFactory_ExecutionEnvironment(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_GIT_BINARY", "") - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", "") + testhelper.Unsetenv(t, "GITALY_TESTING_GIT_BINARY") + testhelper.Unsetenv(t, "GITALY_TESTING_BUNDLED_GIT_PATH") ctx := testhelper.Context(t) @@ -198,7 +198,7 @@ func TestCommandFactory_ExecutionEnvironment(t *testing.T) { }) t.Run("set using GITALY_TESTING_GIT_BINARY", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_GIT_BINARY", "/path/to/env_git") + t.Setenv("GITALY_TESTING_GIT_BINARY", "/path/to/env_git") assertExecEnv(t, config.Cfg{ Git: config.Git{ @@ -234,7 +234,7 @@ func TestCommandFactory_ExecutionEnvironment(t *testing.T) { bundledGitExecutable := filepath.Join(bundledGitDir, "gitaly-git"+suffix) bundledGitRemoteExecutable := filepath.Join(bundledGitDir, "gitaly-git-remote-http"+suffix) - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", bundledGitDir) + t.Setenv("GITALY_TESTING_BUNDLED_GIT_PATH", bundledGitDir) t.Run("missing bin_dir", func(t *testing.T) { _, _, err := git.NewExecCommandFactory(config.Cfg{Git: config.Git{}}, git.WithSkipHooks()) @@ -321,7 +321,7 @@ func TestCommandFactory_ExecutionEnvironment(t *testing.T) { }) t.Run("doesn't exist in the system", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "PATH", "") + testhelper.Unsetenv(t, "PATH") _, _, err := git.NewExecCommandFactory(config.Cfg{}, git.WithSkipHooks()) require.EqualError(t, err, "setting up Git execution environment: could not set up any Git execution environments") diff --git a/internal/git/execution_environment_test.go b/internal/git/execution_environment_test.go index d617227eb..a82910fcb 100644 --- a/internal/git/execution_environment_test.go +++ b/internal/git/execution_environment_test.go @@ -16,7 +16,7 @@ import ( func TestDistributedGitEnvironmentConstructor(t *testing.T) { constructor := git.DistributedGitEnvironmentConstructor{} - testhelper.ModifyEnvironment(t, "GITALY_TESTING_GIT_BINARY", "") + testhelper.Unsetenv(t, "GITALY_TESTING_GIT_BINARY") t.Run("empty configuration fails", func(t *testing.T) { _, err := constructor.Construct(config.Cfg{}) @@ -37,7 +37,7 @@ func TestDistributedGitEnvironmentConstructor(t *testing.T) { }) t.Run("empty configuration with environment override", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_GIT_BINARY", "/foo/bar") + t.Setenv("GITALY_TESTING_GIT_BINARY", "/foo/bar") execEnv, err := constructor.Construct(config.Cfg{}) require.NoError(t, err) @@ -48,7 +48,7 @@ func TestDistributedGitEnvironmentConstructor(t *testing.T) { }) t.Run("configuration overrides environment variable", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_GIT_BINARY", "envvar") + t.Setenv("GITALY_TESTING_GIT_BINARY", "envvar") execEnv, err := constructor.Construct(config.Cfg{ Git: config.Git{ @@ -64,7 +64,7 @@ func TestDistributedGitEnvironmentConstructor(t *testing.T) { } func TestBundledGitEnvironmentConstructor(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", "") + testhelper.Unsetenv(t, "GITALY_TESTING_BUNDLED_GIT_PATH") constructor := git.BundledGitEnvironmentConstructor{} @@ -147,13 +147,13 @@ func TestBundledGitEnvironmentConstructor(t *testing.T) { }) t.Run("bundled Git path without binary directory fails", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", "/does/not/exist") + t.Setenv("GITALY_TESTING_BUNDLED_GIT_PATH", "/does/not/exist") _, err := constructor.Construct(config.Cfg{}) require.Equal(t, errors.New("cannot use bundled binaries without bin path being set"), err) }) t.Run("nonexistent bundled Git path via environment fails", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", "/does/not/exist") + t.Setenv("GITALY_TESTING_BUNDLED_GIT_PATH", "/does/not/exist") _, err := constructor.Construct(config.Cfg{ BinDir: testhelper.TempDir(t), }) @@ -163,7 +163,7 @@ func TestBundledGitEnvironmentConstructor(t *testing.T) { t.Run("incomplete bundled Git environment fails", func(t *testing.T) { bundledGitPath := seedDirWithExecutables(t, "gitaly-git", "gitaly-git-remote-http") - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", bundledGitPath) + t.Setenv("GITALY_TESTING_BUNDLED_GIT_PATH", bundledGitPath) _, err := constructor.Construct(config.Cfg{ BinDir: testhelper.TempDir(t), @@ -174,7 +174,7 @@ func TestBundledGitEnvironmentConstructor(t *testing.T) { t.Run("complete bundled Git environment populates binary directory", func(t *testing.T) { bundledGitPath := seedDirWithExecutables(t, "gitaly-git", "gitaly-git-remote-http", "gitaly-git-http-backend") - testhelper.ModifyEnvironment(t, "GITALY_TESTING_BUNDLED_GIT_PATH", bundledGitPath) + t.Setenv("GITALY_TESTING_BUNDLED_GIT_PATH", bundledGitPath) execEnv, err := constructor.Construct(config.Cfg{ BinDir: testhelper.TempDir(t), @@ -230,7 +230,7 @@ func TestFallbackGitEnvironmentConstructor(t *testing.T) { constructor := git.FallbackGitEnvironmentConstructor{} t.Run("failing lookup of executable causes failure", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "PATH", "/does/not/exist") + t.Setenv("PATH", "/does/not/exist") _, err := constructor.Construct(config.Cfg{}) require.Equal(t, fmt.Errorf("%w: no git executable found in PATH", git.ErrNotConfigured), err) @@ -241,7 +241,7 @@ func TestFallbackGitEnvironmentConstructor(t *testing.T) { gitPath := filepath.Join(tempDir, "git") require.NoError(t, os.WriteFile(gitPath, nil, 0o755)) - testhelper.ModifyEnvironment(t, "PATH", "/does/not/exist:"+tempDir) + t.Setenv("PATH", "/does/not/exist:"+tempDir) execEnv, err := constructor.Construct(config.Cfg{}) require.NoError(t, err) diff --git a/internal/gitaly/server/server_factory_test.go b/internal/gitaly/server/server_factory_test.go index a0cfafd1f..8053b5a1e 100644 --- a/internal/gitaly/server/server_factory_test.go +++ b/internal/gitaly/server/server_factory_test.go @@ -148,7 +148,7 @@ func TestGitalyServerFactory(t *testing.T) { }) t.Run("logging check", func(t *testing.T) { - testhelper.ModifyEnvironment(t, "GITALY_LOG_REQUEST_METHOD_ALLOW_PATTERN", ".") + t.Setenv("GITALY_LOG_REQUEST_METHOD_ALLOW_PATTERN", ".") cfg := testcfg.Build(t) logger, hook := test.NewNullLogger() diff --git a/internal/gitaly/service/repository/create_fork_test.go b/internal/gitaly/service/repository/create_fork_test.go index d4ccd2994..a25c83aa5 100644 --- a/internal/gitaly/service/repository/create_fork_test.go +++ b/internal/gitaly/service/repository/create_fork_test.go @@ -222,8 +222,7 @@ func TestCreateFork_targetExists(t *testing.T) { func injectCustomCATestCerts(t *testing.T) (*x509.CertPool, config.TLS) { certFile, keyFile := testhelper.GenerateCerts(t) - - testhelper.ModifyEnvironment(t, gitalyx509.SSLCertFile, certFile) + t.Setenv(gitalyx509.SSLCertFile, certFile) caPEMBytes := testhelper.MustReadFile(t, certFile) pool := x509.NewCertPool() diff --git a/internal/praefect/checks_test.go b/internal/praefect/checks_test.go index cddaa7849..2c1c3c147 100644 --- a/internal/praefect/checks_test.go +++ b/internal/praefect/checks_test.go @@ -535,7 +535,7 @@ func TestNewClockSyncCheck(t *testing.T) { return true, nil }, setup: func(t *testing.T) { - testhelper.ModifyEnvironment(t, "NTP_HOST", "custom") + t.Setenv("NTP_HOST", "custom") }, }, } { diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go index f7bb2e990..0dd3d3658 100644 --- a/internal/supervisor/supervisor_test.go +++ b/internal/supervisor/supervisor_test.go @@ -179,7 +179,7 @@ func TestNewConfigFromEnv(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { for key, value := range tc.envvars { - testhelper.ModifyEnvironment(t, key, value) + t.Setenv(key, value) } config, err := NewConfigFromEnv() |