Merge pull request #857 from monder/dash-vars

Allow dashes in var names
This commit is contained in:
Alex Dadgar 2016-02-28 16:59:41 -08:00
commit 8a22757a26
2 changed files with 14 additions and 1 deletions

View File

@ -3,7 +3,7 @@ package args
import "regexp"
var (
envRe = regexp.MustCompile(`\${[a-zA-Z0-9_\.]+}`)
envRe = regexp.MustCompile(`\${[a-zA-Z0-9_\-\.]+}`)
)
// ReplaceEnv takes an arg and replaces all occurences of environment variables.

View File

@ -13,6 +13,8 @@ const (
portVal = ":80"
periodKey = "NOMAD.PERIOD"
periodVal = "period"
dashKey = "NOMAD-DASH"
dashVal = "dash"
)
var (
@ -20,6 +22,7 @@ var (
ipKey: ipVal,
portKey: portVal,
periodKey: periodVal,
dashKey: dashVal,
}
)
@ -53,6 +56,16 @@ func TestArgs_ReplaceEnv_Period(t *testing.T) {
}
}
func TestArgs_ReplaceEnv_Dash(t *testing.T) {
input := fmt.Sprintf(`"${%v}"!`, dashKey)
exp := fmt.Sprintf("\"%s\"!", dashVal)
act := ReplaceEnv(input, envVars)
if !reflect.DeepEqual(act, exp) {
t.Fatalf("ReplaceEnv(%v, %v) returned %#v; want %#v", input, envVars, act, exp)
}
}
func TestArgs_ReplaceEnv_Chained(t *testing.T) {
input := fmt.Sprintf("${%s}${%s}", ipKey, portKey)
exp := fmt.Sprintf("%s%s", ipVal, portVal)