Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cli/command/container/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,25 @@ func TestParseEnvfileVariables(t *testing.T) {
}
}

func TestParseEnvfileVariablesWithoutEqualSign(t *testing.T) {
// env without equal sign
config, _, _, err := parseRun([]string{"--env-file=testdata/noequalsign.env", "img", "cmd"})
if err != nil {
t.Fatal(err)
}
if len(config.Env) != 2 || config.Env[0] != "bar=" || config.Env[1] != "demo=true" {
t.Fatalf("Expected a config with [bar= demo=true], got %v", config.Env)
}
t.Setenv("foo", "bar")
config, _, _, err = parseRun([]string{"--env-file=testdata/noequalsign.env", "img", "cmd"})
if err != nil {
t.Fatal(err)
}
if len(config.Env) != 3 || config.Env[0] != "foo=bar" || config.Env[1] != "bar=" || config.Env[2] != "demo=true" {
t.Fatalf("Expected a config with [foo=bar bar= demo=true], got %v", config.Env)
}
}

func TestParseEnvfileVariablesWithBOMUnicode(t *testing.T) {
// UTF8 with BOM
config, _, _, err := parseRun([]string{"--env-file=testdata/utf8.env", "img", "cmd"})
Expand Down Expand Up @@ -1018,6 +1037,24 @@ func TestParseLabelfileVariables(t *testing.T) {
}
}

func TestParseLabelfileVariablesWithoutEqualSign(t *testing.T) {
// label without equal sign
config, _, _, err := parseRun([]string{"--label-file=testdata/noequalsign.label", "img", "cmd"})
if err != nil {
t.Fatal(err)
}
if len(config.Labels) != 3 || config.Labels["demo"] != "true" || config.Labels["foo"] != "" || config.Labels["bar"] != "" {
t.Fatalf("Expected a config with [foo: bar: demo=true], got %v", config.Labels)
}
config, _, _, err = parseRun([]string{"--label-file=testdata/noequalsign.label", "--label=foo=bar", "img", "cmd"})
if err != nil {
t.Fatal(err)
}
if len(config.Labels) != 3 || config.Labels["demo"] != "true" || config.Labels["foo"] != "bar" || config.Labels["bar"] != "" {
t.Fatalf("Expected a config with [foo=bar bar: demo:true], got %v", config.Labels)
}
}

func TestParseEntryPoint(t *testing.T) {
config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"})
assert.NilError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions cli/command/container/testdata/noequalsign.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo
bar=
demo=true
3 changes: 3 additions & 0 deletions cli/command/container/testdata/noequalsign.label
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo
bar=
demo=true
4 changes: 3 additions & 1 deletion opts/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
// ReadKVStrings reads a file of line terminated key=value pairs, and overrides any keys
// present in the file with additional pairs specified in the override parameter
func ReadKVStrings(files []string, override []string) ([]string, error) {
return readKVStrings(files, override, nil)
return readKVStrings(files, override, func(string) (string, bool) {
return "", true
})
}

// ReadKVEnvStrings reads a file of line terminated key=value pairs, and overrides any keys
Expand Down
Loading