Skip to content

Commit

Permalink
Fix override of existing values in prepend & append
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbender authored and pbusko committed Jun 24, 2024
1 parent e366827 commit 10918e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scribe/formatted_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ func NewFormattedMapFromEnvironment(environment map[string]string) FormattedMap
case parts[1] == "override" || parts[1] == "default":
envMap[parts[0]] = value
case parts[1] == "prepend":
envMap[parts[0]] = strings.Join([]string{value, "$" + parts[0]}, environment[parts[0]+".delim"])
if existingValue, ok := envMap[parts[0]]; ok {
envMap[parts[0]] = strings.Join([]string{value, existingValue.(string)}, environment[parts[0]+".delim"])
} else {
envMap[parts[0]] = strings.Join([]string{value, "$" + parts[0]}, environment[parts[0]+".delim"])
}
case parts[1] == "append":
envMap[parts[0]] = strings.Join([]string{"$" + parts[0], value}, environment[parts[0]+".delim"])
if existingValue, ok := envMap[parts[0]]; ok {
envMap[parts[0]] = strings.Join([]string{existingValue.(string), value}, environment[parts[0]+".delim"])
} else {
envMap[parts[0]] = strings.Join([]string{"$" + parts[0], value}, environment[parts[0]+".delim"])
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions scribe/formatted_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ func testFormattedMap(t *testing.T, context spec.G, it spec.S) {
"PREPEND.delim": ":",
"APPEND.append": "some-value",
"APPEND.delim": ":",
"BOTH.append": "appended-value",
"BOTH.delim": ":",
"BOTH.prepend": "prepended-value",
})).To(Equal(scribe.FormattedMap{
"OVERRIDE": "some-value",
"DEFAULT": "some-value",
"PREPEND": "some-value:$PREPEND",
"APPEND": "$APPEND:some-value",
"BOTH": "prepended-value:$BOTH:appended-value",
}))
})
})
Expand Down

0 comments on commit 10918e6

Please # to comment.