Skip to content

Commit 86cdf6c

Browse files
committed
refactor: Simplify yqutil.Join
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent f9ffe3c commit 86cdf6c

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

pkg/yqutil/yqutil.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ func EvaluateExpression(expression string, content []byte) ([]byte, error) {
9393
}
9494

9595
func Join(yqExprs []string) string {
96-
if len(yqExprs) == 0 {
97-
return ""
98-
}
9996
return strings.Join(yqExprs, " | ")
10097
}
10198

pkg/yqutil/yqutil_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,39 @@ foo:
120120
assert.NilError(t, err)
121121
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
122122
}
123+
124+
func TestJoin(t *testing.T) {
125+
tests := []struct {
126+
name string
127+
input []string
128+
expected string
129+
}{
130+
{
131+
name: "multiple values",
132+
input: []string{"foo", "bar", "baz"},
133+
expected: "foo | bar | baz",
134+
},
135+
{
136+
name: "one value",
137+
input: []string{"foo"},
138+
expected: "foo",
139+
},
140+
{
141+
name: "empty values",
142+
input: []string{},
143+
expected: "",
144+
},
145+
{
146+
name: "nil values",
147+
input: nil,
148+
expected: "",
149+
},
150+
}
151+
152+
for _, test := range tests {
153+
t.Run(test.name, func(t *testing.T) {
154+
actual := Join(test.input)
155+
assert.Equal(t, test.expected, actual)
156+
})
157+
}
158+
}

0 commit comments

Comments
 (0)