Browse code

Add some builder getEnv tests

In particular I want to make sure that calling getEnv() when the same
var name appears more than once in the env list that we only pick up
the first one. PR #15182 counts on this

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/08/23 05:12:43
Showing 1 changed files
... ...
@@ -49,3 +49,45 @@ func TestShellParser(t *testing.T) {
49 49
 		}
50 50
 	}
51 51
 }
52
+
53
+func TestGetEnv(t *testing.T) {
54
+	sw := &shellWord{
55
+		word: "",
56
+		envs: nil,
57
+		pos:  0,
58
+	}
59
+
60
+	sw.envs = []string{}
61
+	if sw.getEnv("foo") != "" {
62
+		t.Fatalf("2 - 'foo' should map to ''")
63
+	}
64
+
65
+	sw.envs = []string{"foo"}
66
+	if sw.getEnv("foo") != "" {
67
+		t.Fatalf("3 - 'foo' should map to ''")
68
+	}
69
+
70
+	sw.envs = []string{"foo="}
71
+	if sw.getEnv("foo") != "" {
72
+		t.Fatalf("4 - 'foo' should map to ''")
73
+	}
74
+
75
+	sw.envs = []string{"foo=bar"}
76
+	if sw.getEnv("foo") != "bar" {
77
+		t.Fatalf("5 - 'foo' should map to 'bar'")
78
+	}
79
+
80
+	sw.envs = []string{"foo=bar", "car=hat"}
81
+	if sw.getEnv("foo") != "bar" {
82
+		t.Fatalf("6 - 'foo' should map to 'bar'")
83
+	}
84
+	if sw.getEnv("car") != "hat" {
85
+		t.Fatalf("7 - 'car' should map to 'hat'")
86
+	}
87
+
88
+	// Make sure we grab the first 'car' in the list
89
+	sw.envs = []string{"foo=bar", "car=hat", "car=bike"}
90
+	if sw.getEnv("car") != "hat" {
91
+		t.Fatalf("8 - 'car' should map to 'hat'")
92
+	}
93
+}