-
Notifications
You must be signed in to change notification settings - Fork 23
/
context_test.go
44 lines (35 loc) · 1020 Bytes
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package kubegen
import (
"os"
"reflect"
"testing"
)
func TestContextEnv(t *testing.T) {
os.Clearenv()
os.Setenv("SOMEKEY", "some value")
os.Setenv("KEY_WITH_EMPTY_VALUE", "")
os.Setenv("HAS_MULTIPLE_EQ", "value=foo=baz")
expected := map[string]string{
"SOMEKEY": "some value",
"KEY_WITH_EMPTY_VALUE": "",
"HAS_MULTIPLE_EQ": "value=foo=baz",
}
ctx := Context{}
if !reflect.DeepEqual(ctx.Env(), expected) {
t.Errorf("environment did not parse correctly. Expected [%#v] got [%#v]\n", expected, ctx.Env())
}
}
func TestContextEnvParsedOnce(t *testing.T) {
os.Clearenv()
os.Setenv("SOMEKEY", "some value")
os.Setenv("KEY_WITH_EMPTY_VALUE", "")
os.Setenv("HAS_MULTIPLE_EQ", "value=foo=baz")
ctx := Context{}
first := ctx.Env()
os.Clearenv()
os.Setenv("TOTALLY_DIFFERENT", "value")
second := ctx.Env()
if !reflect.DeepEqual(first, second) {
t.Errorf("Context.Env should only parse the environment once. Expected [%#v] on second call. Got [%#v]\n", first, second)
}
}