Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions namer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ func Test00(t *testing.T) {
assertEndsWith(receivedFile, "namer_test.Test00.received.txt", t)
}

func TestTableDriven(t *testing.T) {
tests := map[string]struct {
approvalFile string
receivedFile string
}{
"test1": {
approvalFile: "namer_test.TestTableDriven.test1.approved.txt",
receivedFile: "namer_test.TestTableDriven.test1.received.txt",
},
"test2": {
approvalFile: "namer_test.TestTableDriven.test2.approved.txt",
receivedFile: "namer_test.TestTableDriven.test2.received.txt",
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
approvalName := getApprovalName(t)

approvalFile := approvalName.getApprovalFile(".txt")
assertEndsWith(approvalFile, test.approvalFile, t)

receivedFile := approvalName.getReceivedFile(".txt")
assertEndsWith(receivedFile, test.receivedFile, t)
})
}
}

func assertEndsWith(s string, ending string, t *testing.T) {
if !strings.HasSuffix(s, ending) {
t.Fatalf("expected name to be '%s', but got %s", ending, s)
Expand Down
12 changes: 12 additions & 0 deletions scrubber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ func TestVerifyMapWithRegexScrubber(t *testing.T) {
approvals.VerifyMap(t, m, opts)
}

func TestVerifyMapWithScrubberAndExtension(t *testing.T) {
scrubber, _ := regexp.Compile("\\d{10}$")
opts := approvals.Options().WithRegexScrubber(scrubber, "<time>").WithExtension(".customExt")

m := map[string]string{
"dog": "bark",
"cat": "meow",
"time": fmt.Sprint(time.Now().Unix()),
}
approvals.VerifyMap(t, m, opts)
}

func TestVerifyArrayWithRegexScrubber(t *testing.T) {
scrubber, _ := regexp.Compile("cat")
opts := approvals.Options().WithRegexScrubber(scrubber, "person")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[cat]=meow
[dog]=bark
[time]=<time>