As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit 70ac7ad2 authored by Igor Drozdov's avatar Igor Drozdov Committed by GitLab
Browse files

Merge branch '700-replace-os-setenv-usage-related-to-testhelper' into 'main'

Replace os.Setenv related to testhelper.go

See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/928



Merged-by: default avatarIgor Drozdov <idrozdov@gitlab.com>
Approved-by: default avatarVasilii Iakliushin <viakliushin@gitlab.com>
Approved-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Co-authored-by: default avatarPatrick Cyiza <jpcyiza@gitlab.com>
parents acc7caba 979b3ebe
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -14,7 +14,7 @@ import (
)
func TestConfigApplyGlobalState(t *testing.T) {
t.Cleanup(testhelper.TempEnv(map[string]string{"SSL_CERT_DIR": "unmodified"}))
testhelper.TempEnv(t, map[string]string{"SSL_CERT_DIR": "unmodified"})
config := &Config{SslCertDir: ""}
config.ApplyGlobalState()
Loading
Loading
Loading
Loading
@@ -52,8 +52,7 @@ func TestNewSuccess(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
restoreEnv := testhelper.TempEnv(tc.environment)
defer restoreEnv()
testhelper.TempEnv(t, tc.environment)
fake := tc.fakeOs
fake.Setup()
Loading
Loading
@@ -89,8 +88,7 @@ func TestNewFailure(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
restoreEnv := testhelper.TempEnv(tc.environment)
defer restoreEnv()
testhelper.TempEnv(t, tc.environment)
fake := tc.fakeOs
fake.Setup()
Loading
Loading
Loading
Loading
@@ -32,8 +32,7 @@ func TestNewFromEnv(t *testing.T) {
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
restoreEnv := testhelper.TempEnv(tc.environment)
defer restoreEnv()
testhelper.TempEnv(t, tc.environment)
require.Equal(t, NewFromEnv(), tc.want)
})
Loading
Loading
@@ -41,9 +40,7 @@ func TestNewFromEnv(t *testing.T) {
}
func TestRemoteAddrFromEnv(t *testing.T) {
cleanup, err := testhelper.Setenv(SSHConnectionEnv, "127.0.0.1 0")
require.NoError(t, err)
defer cleanup()
t.Setenv(SSHConnectionEnv, "127.0.0.1 0")
require.Equal(t, remoteAddrFromEnv(), "127.0.0.1")
}
Loading
Loading
Loading
Loading
@@ -11,17 +11,9 @@ import (
"github.com/stretchr/testify/require"
)
func TempEnv(env map[string]string) func() {
var original = make(map[string]string)
func TempEnv(t *testing.T, env map[string]string) {
for key, value := range env {
original[key] = os.Getenv(key)
os.Setenv(key, value)
}
return func() {
for key, originalValue := range original {
os.Setenv(key, originalValue)
}
t.Setenv(key, value)
}
}
Loading
Loading
@@ -62,9 +54,3 @@ func getTestDataDir() (string, error) {
return path.Join(path.Dir(currentFile), "testdata"), nil
}
func Setenv(key, value string) (func(), error) {
oldValue := os.Getenv(key)
err := os.Setenv(key, value)
return func() { os.Setenv(key, oldValue) }, err
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment