1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/gcs/gcsClient_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

53 lines
1.2 KiB
Go

//go:build unit
// +build unit
package gcs
import (
"os"
"testing"
)
func Test_gcsClient_prepareEnv(t *testing.T) {
os.Setenv("TESTVAR1", "test1")
gcsClient := gcsClient{envVars: []EnvVar{
{Name: "TESTVAR1", Value: "test1_new"},
{Name: "TESTVAR2", Value: "test2_new"},
}}
gcsClient.prepareEnv()
if gcsClient.envVars[0].Modified {
t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[0].Name, false, gcsClient.envVars[0].Modified)
}
if !gcsClient.envVars[1].Modified {
t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[1].Name, true, gcsClient.envVars[1].Modified)
}
os.Setenv("TESTVAR1", "")
os.Setenv("TESTVAR2", "")
}
func TestCleanupEnv(t *testing.T) {
os.Setenv("TESTVAR1", "test1")
os.Setenv("TESTVAR2", "test2")
gcsClient := gcsClient{envVars: []EnvVar{
{Name: "TESTVAR1", Modified: false},
{Name: "TESTVAR2", Modified: true},
}}
gcsClient.cleanupEnv()
if os.Getenv("TESTVAR1") != "test1" {
t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[0].Name, "test1", os.Getenv("TESTVAR1"))
}
if len(os.Getenv("TESTVAR2")) > 0 {
t.Errorf("%v - expected '%v' was '%v'", gcsClient.envVars[1].Name, "", os.Getenv("TESTVAR2"))
}
os.Setenv("TESTVAR1", "")
os.Setenv("TESTVAR2", "")
}