From 7d65ce6a898f215615988a0dfba5d2312bcb4c23 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 27 Oct 2021 16:24:44 +0200 Subject: global: Convert to use `ModifyEnvironment()` Tests shouldn't use `os.Setenv()` and `os.Unsetenv()`, but instead our own `testhelper.ModifyEnvironment()` function which guards us against modifying the environment in parallel tests. Convert tests which do use these functions to use our helper function. --- internal/git/command_factory_test.go | 5 +---- internal/git/hooks/hooks_test.go | 9 ++------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index 6b3157791..c80ea1a84 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -5,7 +5,6 @@ import ( "io" "net/http" "net/http/httptest" - "os" "testing" "github.com/stretchr/testify/require" @@ -26,9 +25,7 @@ func TestGitCommandProxy(t *testing.T) { })) defer ts.Close() - oldHTTPProxy := os.Getenv("http_proxy") - defer require.NoError(t, os.Setenv("http_proxy", oldHTTPProxy)) - require.NoError(t, os.Setenv("http_proxy", ts.URL)) + testhelper.ModifyEnvironment(t, "http_proxy", ts.URL) ctx, cancel := testhelper.Context() defer cancel() diff --git a/internal/git/hooks/hooks_test.go b/internal/git/hooks/hooks_test.go index e094a9c5d..f8d17f5de 100644 --- a/internal/git/hooks/hooks_test.go +++ b/internal/git/hooks/hooks_test.go @@ -1,11 +1,11 @@ package hooks import ( - "os" "testing" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" ) func TestPath(t *testing.T) { @@ -23,12 +23,7 @@ func TestPath(t *testing.T) { }) t.Run("when an env override", func(t *testing.T) { - key := "GITALY_TESTING_NO_GIT_HOOKS" - - require.NoError(t, os.Setenv(key, "1")) - defer func() { - require.NoError(t, os.Unsetenv(key)) - }() + testhelper.ModifyEnvironment(t, "GITALY_TESTING_NO_GIT_HOOKS", "1") require.Equal(t, "/var/empty", Path(cfg)) }) -- cgit v1.2.3