2015-09-26 22:37:48 +00:00
|
|
|
package args
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ipKey = "NOMAD_IP"
|
|
|
|
ipVal = "127.0.0.1"
|
|
|
|
portKey = "NOMAD_PORT_WEB"
|
|
|
|
portVal = ":80"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
envVars = map[string]string{
|
|
|
|
ipKey: ipVal,
|
|
|
|
portKey: portVal,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDriverArgs_ParseAndReplaceInvalidEnv(t *testing.T) {
|
2015-11-18 23:16:42 +00:00
|
|
|
input := []string{"invalid", "$FOO"}
|
2015-09-26 22:37:48 +00:00
|
|
|
exp := []string{"invalid", "$FOO"}
|
2015-11-18 23:16:42 +00:00
|
|
|
act := ParseAndReplace(input, envVars)
|
2015-09-26 22:37:48 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(act, exp) {
|
|
|
|
t.Fatalf("ParseAndReplace(%v, %v) returned %#v; want %#v", input, envVars, act, exp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDriverArgs_ParseAndReplaceValidEnv(t *testing.T) {
|
2015-11-18 23:16:42 +00:00
|
|
|
input := []string{"nomad_ip", fmt.Sprintf(`"$%v"!`, ipKey)}
|
2015-09-26 22:37:48 +00:00
|
|
|
exp := []string{"nomad_ip", fmt.Sprintf("\"%s\"!", ipVal)}
|
2015-11-18 23:16:42 +00:00
|
|
|
act := ParseAndReplace(input, envVars)
|
2015-09-26 22:37:48 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(act, exp) {
|
|
|
|
t.Fatalf("ParseAndReplace(%v, %v) returned %#v; want %#v", input, envVars, act, exp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDriverArgs_ParseAndReplaceChainedEnv(t *testing.T) {
|
2015-11-18 23:16:42 +00:00
|
|
|
input := []string{"-foo", fmt.Sprintf("$%s$%s", ipKey, portKey)}
|
2015-09-26 22:37:48 +00:00
|
|
|
exp := []string{"-foo", fmt.Sprintf("%s%s", ipVal, portVal)}
|
2015-11-18 23:16:42 +00:00
|
|
|
act := ParseAndReplace(input, envVars)
|
2015-09-26 22:37:48 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(act, exp) {
|
|
|
|
t.Fatalf("ParseAndReplace(%v, %v) returned %#v; want %#v", input, envVars, act, exp)
|
|
|
|
}
|
|
|
|
}
|