Skip to content

Commit

Permalink
Merge pull request #857 from monder/dash-vars
Browse files Browse the repository at this point in the history
Allow dashes in var names
  • Loading branch information
dadgar committed Feb 29, 2016
2 parents dd2f82c + 2f10e75 commit dde1e0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helper/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions helper/args/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const (
portVal = ":80"
periodKey = "NOMAD.PERIOD"
periodVal = "period"
dashKey = "NOMAD-DASH"
dashVal = "dash"
)

var (
envVars = map[string]string{
ipKey: ipVal,
portKey: portVal,
periodKey: periodVal,
dashKey: dashVal,
}
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dde1e0a

Please sign in to comment.