Skip to content

Commit

Permalink
config: make formatlist work on lists of length 1
Browse files Browse the repository at this point in the history
removes treat-lists-as-scalar special casing for formatlist

/cc @radeksimko

fixes #2240
  • Loading branch information
phinze committed Jun 25, 2015
1 parent e88aeed commit c95f21c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
10 changes: 0 additions & 10 deletions config/interpolate_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ func interpolationFuncFormatList() ast.Function {

parts := StringList(s).Slice()

// 0 or 1 length lists are treated as scalars and repeated
switch len(parts) {
case 0:
varargs[i-1] = ""
continue
case 1:
varargs[i-1] = parts[0]
continue
}

// otherwise the list is sent down to be indexed
varargs[i-1] = parts

Expand Down
17 changes: 6 additions & 11 deletions config/interpolate_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,18 @@ func TestInterpolateFuncFormatList(t *testing.T) {
"A=1, B=2, C=3",
false,
},
// formatlist of lists of length zero/one are repeated, just as scalars are
{
`${join(", ", formatlist("%s=%s", split(",", ""), split(",", "1,2,3")))}`,
"=1, =2, =3",
false,
},
{
`${join(", ", formatlist("%s=%s", split(",", "A"), split(",", "1,2,3")))}`,
"A=1, A=2, A=3",
false,
},
// Mismatched list lengths generate an error
{
`${formatlist("%s=%2s", split(",", "A,B,C,D"), split(",", "1,2,3"))}`,
nil,
true,
},
// Works with lists of length 1 [GH-2240]
{
`${formatlist("%s.id", split(",", "demo-rest-elb"))}`,
NewStringList([]string{"demo-rest-elb.id"}).String(),
false,
},
},
})
}
Expand Down

0 comments on commit c95f21c

Please sign in to comment.