github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/opts/env_test.go (about) 1 package opts 2 3 import ( 4 "fmt" 5 "os" 6 "runtime" 7 "testing" 8 ) 9 10 func TestValidateEnv(t *testing.T) { 11 valids := map[string]string{ 12 "a": "a", 13 "something": "something", 14 "_=a": "_=a", 15 "env1=value1": "env1=value1", 16 "_env1=value1": "_env1=value1", 17 "env2=value2=value3": "env2=value2=value3", 18 "env3=abc!qwe": "env3=abc!qwe", 19 "env_4=value 4": "env_4=value 4", 20 "PATH": fmt.Sprintf("PATH=%v", os.Getenv("PATH")), 21 "PATH=something": "PATH=something", 22 "asd!qwe": "asd!qwe", 23 "1asd": "1asd", 24 "123": "123", 25 "some space": "some space", 26 " some space before": " some space before", 27 "some space after ": "some space after ", 28 } 29 // Environment variables are case in-sensitive on Windows 30 if runtime.GOOS == "windows" { 31 valids["PaTh"] = fmt.Sprintf("PaTh=%v", os.Getenv("PATH")) 32 } 33 for value, expected := range valids { 34 actual, err := ValidateEnv(value) 35 if err != nil { 36 t.Fatal(err) 37 } 38 if actual != expected { 39 t.Fatalf("Expected [%v], got [%v]", expected, actual) 40 } 41 } 42 }