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