Skip to content

Commit

Permalink
Add tests for system/names
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuhei Kitagawa authored and tekton-robot committed Jun 17, 2019
1 parent 8552f8b commit 3dfea62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/system/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func GetNamespace() string {
if systemNamespace == "" {
return DefaultNamespace
}
return os.Getenv(SystemNamespaceEnvVar)
return systemNamespace
}
35 changes: 35 additions & 0 deletions pkg/system/names_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package system

import (
"os"
"testing"
)

func Test_GetNamespace(t *testing.T) {
testcases := []struct {
envVar string
expectEnvVar string
}{
{
envVar: "",
expectEnvVar: DefaultNamespace,
},
{
envVar: "test",
expectEnvVar: "test",
},
}

value := os.Getenv(SystemNamespaceEnvVar)
defer func() { os.Setenv(SystemNamespaceEnvVar, value) }()

for _, ts := range testcases {
if err := os.Setenv(SystemNamespaceEnvVar, ts.envVar); err != nil {
t.Fatalf("Failed to set ENV: %v", err)
}

if got, want := GetNamespace(), ts.expectEnvVar; got != want {
t.Fatalf("Invalid namespace: got: %v, want: %v", got, want)
}
}
}

0 comments on commit 3dfea62

Please sign in to comment.