Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dashes in var names #857

Merged
merged 1 commit into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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