MCPcopy Create free account
hub / github.com/docker/cli / TestParseEnvfileVariables

Function TestParseEnvfileVariables

cli/command/container/opts_test.go:942–966  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

940}
941
942func TestParseEnvfileVariables(t *testing.T) {
943 expErr := "--env-file: open nonexistent: no such file or directory"
944 if runtime.GOOS == "windows" {
945 expErr = "--env-file: open nonexistent: The system cannot find the file specified."
946 }
947 // env ko
948 if _, _, _, err := parseRun([]string{"--env-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != expErr {
949 t.Fatalf("Expected an error with message '%s', got %v", expErr, err)
950 }
951 // env ok
952 config, _, _, err := parseRun([]string{"--env-file=testdata/valid.env", "img", "cmd"})
953 if err != nil {
954 t.Fatal(err)
955 }
956 if len(config.Env) != 1 || config.Env[0] != "ENV1=value1" {
957 t.Fatalf("Expected a config with [ENV1=value1], got %v", config.Env)
958 }
959 config, _, _, err = parseRun([]string{"--env-file=testdata/valid.env", "--env=ENV2=value2", "img", "cmd"})
960 if err != nil {
961 t.Fatal(err)
962 }
963 if len(config.Env) != 2 || config.Env[0] != "ENV1=value1" || config.Env[1] != "ENV2=value2" {
964 t.Fatalf("Expected a config with [ENV1=value1 ENV2=value2], got %v", config.Env)
965 }
966}
967
968func TestParseEnvfileVariablesWithBOMUnicode(t *testing.T) {
969 // UTF8 with BOM

Callers

nothing calls this directly

Calls 2

parseRunFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…