Skip to content

Commit b99ed70

Browse files
committed
. t Add several new tests
1 parent 39df8b5 commit b99ed70

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

approval_name_test.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import (
66
)
77

88
func TestNamer(t *testing.T) {
9-
t.Parallel()
9+
t.Parallel()
1010
name, _ := getApprovalName(t)
1111
if !strings.HasSuffix(name, "TestNamer") {
1212
t.Fatalf("test name is wrong in namer, got %s", name)
1313
}
1414
}
1515

1616
func TestNamerFilename(t *testing.T) {
17-
t.Parallel()
17+
t.Parallel()
1818
_, fileName := getApprovalName(t)
1919
if !strings.HasSuffix(fileName, "approval_name_test.go") {
2020
t.Fatalf("test filename is wrong in namer, got %s", fileName)
2121
}
2222
}
2323

2424
func TestParameterizedTestNames(t *testing.T) {
25-
t.Parallel()
25+
t.Parallel()
2626
for _, tc := range ExampleParameterizedTestcases {
2727
tc := tc
2828
t.Run(tc.name, func(t *testing.T) {
@@ -35,3 +35,32 @@ func TestParameterizedTestNames(t *testing.T) {
3535
})
3636
}
3737
}
38+
39+
func TestTableDriven(t *testing.T) {
40+
t.Parallel()
41+
tests := map[string]struct {
42+
approvalFile string
43+
receivedFile string
44+
}{
45+
"test1": {
46+
approvalFile: "approval_name_test.TestTableDriven.test1.approved.txt",
47+
receivedFile: "approval_name_test.TestTableDriven.test1.received.txt",
48+
},
49+
"test2": {
50+
approvalFile: "approval_name_test.TestTableDriven.test2.approved.txt",
51+
receivedFile: "approval_name_test.TestTableDriven.test2.received.txt",
52+
},
53+
}
54+
55+
for name, test := range tests {
56+
t.Run(name, func(t *testing.T) {
57+
approvalName := getApprovalNameCreator()(t)
58+
59+
approvalFile := approvalName.GetApprovalFile(".txt")
60+
assertEndsWith(approvalFile, test.approvalFile, t)
61+
62+
receivedFile := approvalName.GetReceivedFile(".txt")
63+
assertEndsWith(receivedFile, test.receivedFile, t)
64+
})
65+
}
66+
}

scrubber_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ func TestVerifyMapWithRegexScrubber(t *testing.T) {
3737
approvals.VerifyMap(t, m, opts)
3838
}
3939

40+
func TestVerifyMapWithScrubberAndExtension(t *testing.T) {
41+
t.Parallel()
42+
scrubber, _ := regexp.Compile("\\d{10}$")
43+
opts := approvals.Options().WithRegexScrubber(scrubber, "<time>").ForFile().WithExtension(".customExt")
44+
45+
m := map[string]string{
46+
"dog": "bark",
47+
"cat": "meow",
48+
"time": fmt.Sprint(time.Now().Unix()),
49+
}
50+
approvals.VerifyMap(t, m, opts)
51+
}
52+
4053
func TestVerifyArrayWithRegexScrubber(t *testing.T) {
4154
t.Parallel()
4255
scrubber, _ := regexp.Compile("cat")
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)