Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-05 10:15:04 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-06 08:56:49 +0300
commitf980e468853745fef7cf8d0a83623eda4646e54d (patch)
tree595d7eea13d949af7c9fe8a320a63a75da2d1f10
parent1bfcfe3eb54c2116915ed1a39a8e2eb8ba809339 (diff)
testhelper: Use `t.Setenv()` to detect misuse with `t.Parallel()`
When using `os.Setenv()`, we change the environment variable for the full process. While not surprising, this means that we must avoid this in parallel tests given that the environment variable would also be set for any other, currently running tests. With Go v1.17 a new `t.Setenv()` helper function has been introduced that detects this case and that instead causes us to panic. Convert `testhelper.ModifyEnvironment()` to use that function and fix a test that is using `t.Parallel()`.
-rw-r--r--internal/gitaly/service/repository/create_fork_test.go2
-rw-r--r--internal/testhelper/testhelper.go15
2 files changed, 6 insertions, 11 deletions
diff --git a/internal/gitaly/service/repository/create_fork_test.go b/internal/gitaly/service/repository/create_fork_test.go
index b23b85bc3..53651c408 100644
--- a/internal/gitaly/service/repository/create_fork_test.go
+++ b/internal/gitaly/service/repository/create_fork_test.go
@@ -43,8 +43,6 @@ import (
)
func TestCreateFork_successful(t *testing.T) {
- t.Parallel()
-
// We need to inject this once across all tests given that crypto/x509 only initializes
// certificates once. Changing injected certs during our tests is thus not going to fly well
// and would cause failure. We should eventually address this and provide better testing
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index db65feeb3..dacf805b3 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -274,17 +274,14 @@ func ModifyEnvironment(t testing.TB, key string, value string) {
oldValue, hasOldValue := os.LookupEnv(key)
if value == "" {
require.NoError(t, os.Unsetenv(key))
+ t.Cleanup(func() {
+ if hasOldValue {
+ require.NoError(t, os.Setenv(key, oldValue))
+ }
+ })
} else {
- require.NoError(t, os.Setenv(key, value))
+ t.Setenv(key, value)
}
-
- t.Cleanup(func() {
- if hasOldValue {
- require.NoError(t, os.Setenv(key, oldValue))
- } else {
- require.NoError(t, os.Unsetenv(key))
- }
- })
}
// GenerateCerts creates a certificate that can be used to establish TLS protected TCP connection.