Skip to content

Commit

Permalink
Do not mutate Role.Options when RenderScripts is called
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnugget committed Mar 6, 2016
1 parent f2e36dc commit b7750a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion models/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Role struct {

func (r *Role) RenderScripts(options map[string]string) (map[DeploymentStage]string, error) {
rendered := make(map[DeploymentStage]string)
mergedOptions := mergeOptions(r.Options, options)
mergedOptions := mergeOptions(copyOptions(r.Options), options)

for stage, scriptTemplate := range r.ScriptTemplates {
var b bytes.Buffer
Expand All @@ -40,3 +40,11 @@ func mergeOptions(o1 map[string]string, o2 map[string]string) map[string]string
}
return o1
}

func copyOptions(options map[string]string) map[string]string {
result := make(map[string]string)
for key, value := range options {
result[key] = value
}
return result
}
6 changes: 6 additions & 0 deletions models/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ func TestRender(t *testing.T) {
t.Errorf("Rendering wrong. expected='%s', got='%s'", expectedScript, result[stage])
}
}

for name, _ := range otherOptions {
if role.Options[name] != "" {
t.Errorf("role.Options[%s] to be nil, got=%s", name, role.Options[name])
}
}
}
}

0 comments on commit b7750a2

Please sign in to comment.