|
1 | 1 | package utils |
2 | 2 |
|
3 | | -import "testing" |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + . "github.com/smartystreets/goconvey/convey" |
| 7 | +) |
4 | 8 |
|
5 | 9 | 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 | + }) |
11 | 16 | } |
12 | 17 |
|
13 | 18 | 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 | + }) |
37 | 25 | } |
38 | 26 |
|
39 | 27 | 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 | + }) |
60 | 44 | } |
0 commit comments