Merge pull request #518 from yui-knk/add_test_for_addEnv
Add test cases for `addEnv` which is a bit complicated functiondocker-18.09
commit
db8b382274
|
@ -62,3 +62,53 @@ COPY --from=0 f2 /
|
|||
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestAddEnv(t *testing.T) {
|
||||
// k exists in env as key
|
||||
// override = false
|
||||
env := []string{"key1=val1", "key2=val2"}
|
||||
result := addEnv(env, "key1", "value1", false)
|
||||
assert.Equal(t, []string{"key1=val1", "key2=val2"}, result)
|
||||
|
||||
// k exists in env as key
|
||||
// override = true
|
||||
env = []string{"key1=val1", "key2=val2"}
|
||||
result = addEnv(env, "key1", "value1", true)
|
||||
assert.Equal(t, []string{"key1=value1", "key2=val2"}, result)
|
||||
|
||||
// k does not exist in env as key
|
||||
// override = false
|
||||
env = []string{"key1=val1", "key2=val2"}
|
||||
result = addEnv(env, "key3", "val3", false)
|
||||
assert.Equal(t, []string{"key1=val1", "key2=val2", "key3=val3"}, result)
|
||||
|
||||
// k does not exist in env as key
|
||||
// override = true
|
||||
env = []string{"key1=val1", "key2=val2"}
|
||||
result = addEnv(env, "key3", "val3", true)
|
||||
assert.Equal(t, []string{"key1=val1", "key2=val2", "key3=val3"}, result)
|
||||
|
||||
// env has same keys
|
||||
// override = false
|
||||
env = []string{"key1=val1", "key1=val2"}
|
||||
result = addEnv(env, "key1", "value1", false)
|
||||
assert.Equal(t, []string{"key1=val1", "key1=val2"}, result)
|
||||
|
||||
// env has same keys
|
||||
// override = true
|
||||
env = []string{"key1=val1", "key1=val2"}
|
||||
result = addEnv(env, "key1", "value1", true)
|
||||
assert.Equal(t, []string{"key1=value1", "key1=val2"}, result)
|
||||
|
||||
// k matches with key only string in env
|
||||
// override = false
|
||||
env = []string{"key1=val1", "key2=val2", "key3"}
|
||||
result = addEnv(env, "key3", "val3", false)
|
||||
assert.Equal(t, []string{"key1=val1", "key2=val2", "key3"}, result)
|
||||
|
||||
// k matches with key only string in env
|
||||
// override = true
|
||||
env = []string{"key1=val1", "key2=val2", "key3"}
|
||||
result = addEnv(env, "key3", "val3", true)
|
||||
assert.Equal(t, []string{"key1=val1", "key2=val2", "key3=val3"}, result)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue