github.com/jaylevin/jenkins-library@v1.230.4/pkg/gcs/gcsClient_test.go (about) 1 package gcs 2 3 import ( 4 "os" 5 "testing" 6 ) 7 8 func Test_gcsClient_prepareEnv(t *testing.T) { 9 os.Setenv("TESTVAR1", "test1") 10 11 gcsClient := gcsClient{envVars: []EnvVar{ 12 {Name: "TESTVAR1", Value: "test1_new"}, 13 {Name: "TESTVAR2", Value: "test2_new"}, 14 }} 15 16 gcsClient.prepareEnv() 17 18 if gcsClient.envVars[0].Modified { 19 t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[0].Name, false, gcsClient.envVars[0].Modified) 20 } 21 if !gcsClient.envVars[1].Modified { 22 t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[1].Name, true, gcsClient.envVars[1].Modified) 23 } 24 25 os.Setenv("TESTVAR1", "") 26 os.Setenv("TESTVAR2", "") 27 } 28 29 func TestCleanupEnv(t *testing.T) { 30 os.Setenv("TESTVAR1", "test1") 31 os.Setenv("TESTVAR2", "test2") 32 33 gcsClient := gcsClient{envVars: []EnvVar{ 34 {Name: "TESTVAR1", Modified: false}, 35 {Name: "TESTVAR2", Modified: true}, 36 }} 37 38 gcsClient.cleanupEnv() 39 40 if os.Getenv("TESTVAR1") != "test1" { 41 t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[0].Name, "test1", os.Getenv("TESTVAR1")) 42 } 43 if len(os.Getenv("TESTVAR2")) > 0 { 44 t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[1].Name, "", os.Getenv("TESTVAR2")) 45 } 46 47 os.Setenv("TESTVAR1", "") 48 os.Setenv("TESTVAR2", "") 49 }