|
@@ -377,35 +377,23 @@ func TestValidateDevice(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestValidateEnv(t *testing.T) {
|
|
|
- invalids := map[string]string{
|
|
|
- "some spaces": "poorly formatted environment: variable 'some spaces' is not a valid environment variable",
|
|
|
- "asd!qwe": "poorly formatted environment: variable 'asd!qwe' is not a valid environment variable",
|
|
|
- "1asd": "poorly formatted environment: variable '1asd' is not a valid environment variable",
|
|
|
- "123": "poorly formatted environment: variable '123' is not a valid environment variable",
|
|
|
- }
|
|
|
valids := map[string]string{
|
|
|
- "a": "a",
|
|
|
- "something": "something",
|
|
|
- "_=a": "_=a",
|
|
|
- "env1=value1": "env1=value1",
|
|
|
- "_env1=value1": "_env1=value1",
|
|
|
- "env2=value2=value3": "env2=value2=value3",
|
|
|
- "env3=abc!qwe": "env3=abc!qwe",
|
|
|
- "env_4=value 4": "env_4=value 4",
|
|
|
- "PATH": fmt.Sprintf("PATH=%v", os.Getenv("PATH")),
|
|
|
- "PATH=something": "PATH=something",
|
|
|
- }
|
|
|
- for value, expectedError := range invalids {
|
|
|
- _, err := ValidateEnv(value)
|
|
|
- if err == nil {
|
|
|
- t.Fatalf("Expected ErrBadEnvVariable, got nothing")
|
|
|
- }
|
|
|
- if _, ok := err.(ErrBadEnvVariable); !ok {
|
|
|
- t.Fatalf("Expected ErrBadEnvVariable, got [%s]", err)
|
|
|
- }
|
|
|
- if err.Error() != expectedError {
|
|
|
- t.Fatalf("Expected ErrBadEnvVariable with message [%s], got [%s]", expectedError, err.Error())
|
|
|
- }
|
|
|
+ "a": "a",
|
|
|
+ "something": "something",
|
|
|
+ "_=a": "_=a",
|
|
|
+ "env1=value1": "env1=value1",
|
|
|
+ "_env1=value1": "_env1=value1",
|
|
|
+ "env2=value2=value3": "env2=value2=value3",
|
|
|
+ "env3=abc!qwe": "env3=abc!qwe",
|
|
|
+ "env_4=value 4": "env_4=value 4",
|
|
|
+ "PATH": fmt.Sprintf("PATH=%v", os.Getenv("PATH")),
|
|
|
+ "PATH=something": "PATH=something",
|
|
|
+ "asd!qwe": "asd!qwe",
|
|
|
+ "1asd": "1asd",
|
|
|
+ "123": "123",
|
|
|
+ "some space": "some space",
|
|
|
+ " some space before": " some space before",
|
|
|
+ "some space after ": "some space after ",
|
|
|
}
|
|
|
for value, expected := range valids {
|
|
|
actual, err := ValidateEnv(value)
|