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 06913778 authored by Igor Drozdov's avatar Igor Drozdov Committed by GitLab
Browse files

Merge branch '700-replace-os-setenv-in-command-test' into 'main'

Replace os.Setenv by testing.Setenv in command_test.go

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



Merged-by: default avatarIgor Drozdov <idrozdov@gitlab.com>
Approved-by: default avatarVasilii Iakliushin <viakliushin@gitlab.com>
Approved-by: default avatarIgor Drozdov <idrozdov@gitlab.com>
Co-authored-by: default avatarPatrick Cyiza <jpcyiza@gitlab.com>
parents dd47a204 63adaeb8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -30,8 +30,7 @@ func TestSetup(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
resetEnvironment := addAdditionalEnv(tc.additionalEnv)
defer resetEnvironment()
addAdditionalEnv(t, tc.additionalEnv)
ctx, finished := Setup("foo", &config.Config{})
defer finished()
Loading
Loading
@@ -54,27 +53,9 @@ func TestSetup(t *testing.T) {
// addAdditionalEnv will configure additional environment values
// and return a deferrable function to reset the environment to
// it's original state after the test
func addAdditionalEnv(envMap map[string]string) func() {
prevValues := map[string]string{}
unsetValues := []string{}
func addAdditionalEnv(t *testing.T, envMap map[string]string) {
for k, v := range envMap {
value, exists := os.LookupEnv(k)
if exists {
prevValues[k] = value
} else {
unsetValues = append(unsetValues, k)
}
os.Setenv(k, v)
}
return func() {
for k, v := range prevValues {
os.Setenv(k, v)
}
for _, k := range unsetValues {
os.Unsetenv(k)
}
t.Setenv(k, v)
}
}
Loading
Loading
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