Skip to content

Commit 83c241d

Browse files
committed
Converted utils tests to convey
1 parent ba880ba commit 83c241d

File tree

1 file changed

+33
-49
lines changed

1 file changed

+33
-49
lines changed

pkg/utils/utils_test.go

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,44 @@
11
package utils
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
. "github.com/smartystreets/goconvey/convey"
7+
)
48

59
func TestWordify(t *testing.T) {
6-
actual := Wordify("Hello World 42 !!")
7-
expected := "Hello_World_42"
8-
if actual != expected {
9-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
10-
}
10+
Convey("Testing Wordify()", t, func() {
11+
So(Wordify("Hello World 42 !!"), ShouldEqual, "Hello_World_42")
12+
So(Wordify(" Hello World 42 !! "), ShouldEqual, "Hello_World_42")
13+
So(Wordify("Hello_World_42"), ShouldEqual, "Hello_World_42")
14+
So(Wordify(""), ShouldEqual, "")
15+
})
1116
}
1217

1318
func TestTruncIf(t *testing.T) {
14-
actual := TruncIf("Hello World", 5, false)
15-
expected := "Hello World"
16-
if actual != expected {
17-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
18-
}
19-
20-
actual = TruncIf("Hello World", 5, true)
21-
expected = "Hello"
22-
if actual != expected {
23-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
24-
}
25-
26-
actual = TruncIf("Hello World", 50, false)
27-
expected = "Hello World"
28-
if actual != expected {
29-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
30-
}
31-
32-
actual = TruncIf("Hello World", 50, true)
33-
expected = "Hello World"
34-
if actual != expected {
35-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
36-
}
19+
Convey("Testing TruncIf()", t, func() {
20+
So(TruncIf("Hello World", 5, false), ShouldEqual, "Hello World")
21+
So(TruncIf("Hello World", 5, true), ShouldEqual, "Hello")
22+
So(TruncIf("Hello World", 50, false), ShouldEqual, "Hello World")
23+
So(TruncIf("Hello World", 50, true), ShouldEqual, "Hello World")
24+
})
3725
}
3826

3927
func TestPathToTARPathparts(t *testing.T) {
40-
dir, base := PathToTARPathparts("/etc/passwd")
41-
expected := []string{"/etc", "passwd"}
42-
actual := []string{dir, base}
43-
if actual[0] != expected[0] || actual[1] != expected[1] {
44-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
45-
}
46-
47-
dir, base = PathToTARPathparts("/etc")
48-
expected = []string{"/", "etc"}
49-
actual = []string{dir, base}
50-
if actual[0] != expected[0] || actual[1] != expected[1] {
51-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
52-
}
53-
54-
dir, base = PathToTARPathparts("/etc/")
55-
expected = []string{"/", "etc"}
56-
actual = []string{dir, base}
57-
if actual[0] != expected[0] || actual[1] != expected[1] {
58-
t.Errorf("returned value is invalid [actual: %s][expected: %s]", actual, expected)
59-
}
28+
Convey("Testing PathToTARPathparts()", t, func() {
29+
dir, base := PathToTARPathparts("/etc/passwd")
30+
So([]string{"/etc", "passwd"}, ShouldResemble, []string{dir, base})
31+
32+
dir, base = PathToTARPathparts("/etc")
33+
So([]string{"/", "etc"}, ShouldResemble, []string{dir, base})
34+
35+
dir, base = PathToTARPathparts("/etc/")
36+
So([]string{"/", "etc"}, ShouldResemble, []string{dir, base})
37+
38+
dir, base = PathToTARPathparts("/long/path/to/file")
39+
So([]string{"/long/path/to", "file"}, ShouldResemble, []string{dir, base})
40+
41+
dir, base = PathToTARPathparts("/long/path/to/dir/")
42+
So([]string{"/long/path/to", "dir"}, ShouldResemble, []string{dir, base})
43+
})
6044
}

0 commit comments

Comments
 (0)