github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/client/driver/args/args_test.go (about) 1 package args 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 ) 8 9 const ( 10 ipKey = "NOMAD_IP" 11 ipVal = "127.0.0.1" 12 portKey = "NOMAD_PORT_WEB" 13 portVal = ":80" 14 ) 15 16 var ( 17 envVars = map[string]string{ 18 ipKey: ipVal, 19 portKey: portVal, 20 } 21 ) 22 23 func TestDriverArgs_ParseAndReplaceInvalidEnv(t *testing.T) { 24 input := []string{"invalid", "$FOO"} 25 exp := []string{"invalid", "$FOO"} 26 act := ParseAndReplace(input, envVars) 27 28 if !reflect.DeepEqual(act, exp) { 29 t.Fatalf("ParseAndReplace(%v, %v) returned %#v; want %#v", input, envVars, act, exp) 30 } 31 } 32 33 func TestDriverArgs_ParseAndReplaceValidEnv(t *testing.T) { 34 input := []string{"nomad_ip", fmt.Sprintf(`"$%v"!`, ipKey)} 35 exp := []string{"nomad_ip", fmt.Sprintf("\"%s\"!", ipVal)} 36 act := ParseAndReplace(input, envVars) 37 38 if !reflect.DeepEqual(act, exp) { 39 t.Fatalf("ParseAndReplace(%v, %v) returned %#v; want %#v", input, envVars, act, exp) 40 } 41 } 42 43 func TestDriverArgs_ParseAndReplaceChainedEnv(t *testing.T) { 44 input := []string{"-foo", fmt.Sprintf("$%s$%s", ipKey, portKey)} 45 exp := []string{"-foo", fmt.Sprintf("%s%s", ipVal, portVal)} 46 act := ParseAndReplace(input, envVars) 47 48 if !reflect.DeepEqual(act, exp) { 49 t.Fatalf("ParseAndReplace(%v, %v) returned %#v; want %#v", input, envVars, act, exp) 50 } 51 }