Skip to content

Commit 6262b6b

Browse files
committed
t - Add tests cases
- Test using both scrubber and file extension options - Test namer when using table driven tests
1 parent 32d5677 commit 6262b6b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

namer_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ func Test00(t *testing.T) {
1515
assertEndsWith(receivedFile, "namer_test.Test00.received.txt", t)
1616
}
1717

18+
func TestTableDriven(t *testing.T) {
19+
tests := map[string]struct {
20+
approvalFile string
21+
receivedFile string
22+
}{
23+
"test1": {
24+
approvalFile: "namer_test.TestTableDriven.test1.approved.txt",
25+
receivedFile: "namer_test.TestTableDriven.test1.received.txt",
26+
},
27+
"test2": {
28+
approvalFile: "namer_test.TestTableDriven.test2.approved.txt",
29+
receivedFile: "namer_test.TestTableDriven.test2.received.txt",
30+
},
31+
}
32+
33+
for name, test := range tests {
34+
t.Run(name, func(t *testing.T) {
35+
approvalName := getApprovalName(t)
36+
37+
approvalFile := approvalName.getApprovalFile(".txt")
38+
assertEndsWith(approvalFile, test.approvalFile, t)
39+
40+
receivedFile := approvalName.getReceivedFile(".txt")
41+
assertEndsWith(receivedFile, test.receivedFile, t)
42+
})
43+
}
44+
}
45+
1846
func assertEndsWith(s string, ending string, t *testing.T) {
1947
if !strings.HasSuffix(s, ending) {
2048
t.Fatalf("expected name to be '%s', but got %s", ending, s)

scrubber_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ func TestVerifyMapWithRegexScrubber(t *testing.T) {
3535
approvals.VerifyMap(t, m, opts)
3636
}
3737

38+
func TestVerifyMapWithScrubberAndExtension(t *testing.T) {
39+
scrubber, _ := regexp.Compile("\\d{10}$")
40+
opts := approvals.Options().WithRegexScrubber(scrubber, "<time>").WithExtension(".customExt")
41+
42+
m := map[string]string{
43+
"dog": "bark",
44+
"cat": "meow",
45+
"time": fmt.Sprint(time.Now().Unix()),
46+
}
47+
approvals.VerifyMap(t, m, opts)
48+
}
49+
3850
func TestVerifyArrayWithRegexScrubber(t *testing.T) {
3951
scrubber, _ := regexp.Compile("cat")
4052
opts := approvals.Options().WithRegexScrubber(scrubber, "person")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[cat]=meow
2+
[dog]=bark
3+
[time]=<time>

0 commit comments

Comments
 (0)