-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathapproval_name_test.go
More file actions
66 lines (58 loc) · 1.68 KB
/
approval_name_test.go
File metadata and controls
66 lines (58 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package approvals
import (
"strings"
"testing"
)
func TestNamer(t *testing.T) {
t.Parallel()
name, _ := getApprovalName(t)
if !strings.HasSuffix(name, "TestNamer") {
t.Fatalf("test name is wrong in namer, got %s", name)
}
}
func TestNamerFilename(t *testing.T) {
t.Parallel()
_, fileName := getApprovalName(t)
if !strings.HasSuffix(fileName, "approval_name_test.go") {
t.Fatalf("test filename is wrong in namer, got %s", fileName)
}
}
func TestParameterizedTestNames(t *testing.T) {
t.Parallel()
for _, tc := range ExampleParameterizedTestcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
name, _ := getApprovalName(t)
sanitizedName := strings.Replace(tc.name, " ", "_", -1)
if !strings.Contains(name, "TestParameterizedTestNames.") &&
!strings.HasSuffix(name, sanitizedName) {
t.Fatalf("parameterized test name is wrong in namer, got %s", name)
}
})
}
}
func TestTableDriven(t *testing.T) {
t.Parallel()
tests := map[string]struct {
approvalFile string
receivedFile string
}{
"test1": {
approvalFile: "approval_name_test.TestTableDriven.test1.approved.txt",
receivedFile: "approval_name_test.TestTableDriven.test1.received.txt",
},
"test2": {
approvalFile: "approval_name_test.TestTableDriven.test2.approved.txt",
receivedFile: "approval_name_test.TestTableDriven.test2.received.txt",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
approvalName := getApprovalNameCreator()(t)
approvalFile := approvalName.GetApprovalFile(".txt")
assertEndsWith(approvalFile, test.approvalFile, t)
receivedFile := approvalName.GetReceivedFile(".txt")
assertEndsWith(receivedFile, test.receivedFile, t)
})
}
}