Skip to content

Commit eeeae2c

Browse files
author
Doug Davis
committed
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 moby#15182 counts on this Signed-off-by: Doug Davis <[email protected]>
1 parent efabc8e commit eeeae2c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

builder/shell_parser_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,45 @@ func TestShellParser(t *testing.T) {
4949
}
5050
}
5151
}
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+
}

0 commit comments

Comments
 (0)