Skip to content

Commit 961c31a

Browse files
committed
test(util): add unit test for string util
1 parent d1a345b commit 961c31a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/util/strings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ func StringsFallback3(val1 string, val2 string, val3 string) string {
1010

1111
func stringsFallback(vals ...string) string {
1212
for _, v := range vals {
13-
if v != "" {
14-
return v
15-
}
13+
if v != "" {
14+
return v
15+
}
1616
}
1717
return ""
1818
}

pkg/util/strings_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package util
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/smartystreets/goconvey/convey"
7+
)
8+
9+
func TestStringsUtil(t *testing.T) {
10+
Convey("Falling back until none empty string", t, func() {
11+
So(StringsFallback2("1", "2"), ShouldEqual, "1")
12+
So(StringsFallback2("", "2"), ShouldEqual, "2")
13+
So(StringsFallback3("", "", "3"), ShouldEqual, "3")
14+
})
15+
}

0 commit comments

Comments
 (0)