open-nomad/helper/args/args_test.go

52 lines
1.2 KiB
Go
Raw Normal View History

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) {
input := []string{"invalid", "$FOO"}
2015-09-26 22:37:48 +00:00
exp := []string{"invalid", "$FOO"}
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) {
input := []string{"nomad_ip", fmt.Sprintf(`"$%v"!`, ipKey)}
2015-09-26 22:37:48 +00:00
exp := []string{"nomad_ip", fmt.Sprintf("\"%s\"!", ipVal)}
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) {
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)}
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)
}
}