| 940 | } |
| 941 | |
| 942 | func 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 | |
| 968 | func TestParseEnvfileVariablesWithBOMUnicode(t *testing.T) { |
| 969 | // UTF8 with BOM |