Skip to content

Commit eb5c0e5

Browse files
committed
. t parallelize tests + add names to TestFailable usage
1 parent bc8ef1b commit eb5c0e5

8 files changed

+47
-10
lines changed

approval_name_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ import (
66
)
77

88
func TestNamer(t *testing.T) {
9+
t.Parallel()
910
name, _ := getApprovalName(t)
1011
if !strings.HasSuffix(name, "TestNamer") {
1112
t.Fatalf("test name is wrong in namer, got %s", name)
1213
}
1314
}
1415

1516
func TestNamerFilename(t *testing.T) {
17+
t.Parallel()
1618
_, fileName := getApprovalName(t)
1719
if !strings.HasSuffix(fileName, "approval_name_test.go") {
1820
t.Fatalf("test filename is wrong in namer, got %s", fileName)
1921
}
2022
}
2123

2224
func TestParameterizedTestNames(t *testing.T) {
25+
t.Parallel()
2326
for _, tc := range ExampleParameterizedTestcases {
2427
tc := tc
2528
t.Run(tc.name, func(t *testing.T) {

approvals_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestMain(m *testing.M) {
2323
// end-snippet
2424

2525
func TestVerifyStringApproval(t *testing.T) {
26+
t.Parallel()
2627
// begin-snippet: inline_reporter
2728
r := UseReporter(reporters.NewContinuousIntegrationReporter())
2829
defer r.Close()
@@ -32,6 +33,7 @@ func TestVerifyStringApproval(t *testing.T) {
3233
}
3334

3435
func TestReporterFromSetup(t *testing.T) {
36+
t.Parallel()
3537
VerifyString(t, hello("World"))
3638
}
3739

@@ -53,16 +55,17 @@ func hello(name string) string {
5355
}
5456

5557
func TestParameterizedTests(t *testing.T) {
56-
t.Parallel()
5758
for _, tc := range ExampleParameterizedTestcases {
5859
tc := tc
5960
t.Run(tc.name, func(t *testing.T) {
61+
t.Parallel()
6062
VerifyString(t, hello(tc.value))
6163
})
6264
}
6365
}
6466

6567
func TestVerifyXMLStruct(t *testing.T) {
68+
t.Parallel()
6669
json := struct {
6770
XMLName xml.Name `xml:"Test"`
6871
Title string
@@ -78,6 +81,7 @@ func TestVerifyXMLStruct(t *testing.T) {
7881
}
7982

8083
func TestVerifyBadXMLStruct(t *testing.T) {
84+
t.Parallel()
8185
xmlContent := struct {
8286
Title string
8387
}{
@@ -88,16 +92,19 @@ func TestVerifyBadXMLStruct(t *testing.T) {
8892
}
8993

9094
func TestVerifyXMLBytes(t *testing.T) {
95+
t.Parallel()
9196
xmlb := []byte("<Test><Title>Hello World!</Title><Name>Peter Pan</Name><Age>100</Age></Test>")
9297
VerifyXMLBytes(t, xmlb)
9398
}
9499

95100
func TestVerifyBadXMLBytes(t *testing.T) {
101+
t.Parallel()
96102
xmlb := []byte("Test></Test>")
97103
VerifyXMLBytes(t, xmlb)
98104
}
99105

100106
func TestVerifyJSONStruct(t *testing.T) {
107+
t.Parallel()
101108
json := struct {
102109
Title string
103110
Name string
@@ -112,16 +119,19 @@ func TestVerifyJSONStruct(t *testing.T) {
112119
}
113120

114121
func TestVerifyJSONBytes(t *testing.T) {
122+
t.Parallel()
115123
jsonb := []byte("{ \"foo\": \"bar\", \"age\": 42, \"bark\": \"woof\" }")
116124
VerifyJSONBytes(t, jsonb)
117125
}
118126

119127
func TestVerifyBadJSONBytes(t *testing.T) {
128+
t.Parallel()
120129
jsonb := []byte("{ foo: \"bar\", \"age\": 42, \"bark\": \"woof\" }")
121130
VerifyJSONBytes(t, jsonb)
122131
}
123132

124133
func TestVerifyMap(t *testing.T) {
134+
t.Parallel()
125135
m := map[string]string{
126136
"dog": "bark",
127137
"cat": "meow",
@@ -131,41 +141,49 @@ func TestVerifyMap(t *testing.T) {
131141
}
132142

133143
func TestVerifyMapBadMap(t *testing.T) {
144+
t.Parallel()
134145
m := "foo"
135146
VerifyMap(t, m)
136147
}
137148

138149
func TestVerifyMapEmptyMap(t *testing.T) {
150+
t.Parallel()
139151
m := map[string]string{}
140152
VerifyMap(t, m)
141153
}
142154

143155
func TestVerifyArray(t *testing.T) {
156+
t.Parallel()
144157
xs := []string{"dog", "cat", "bird"}
145158
VerifyArray(t, xs)
146159
}
147160

148161
func TestVerifyArrayBadArray(t *testing.T) {
162+
t.Parallel()
149163
xs := "string"
150164
VerifyArray(t, xs)
151165
}
152166

153167
func TestVerifyArrayEmptyArray(t *testing.T) {
168+
t.Parallel()
154169
var xs []string
155170
VerifyArray(t, xs)
156171
}
157172

158173
func TestVerifyArrayTransformation(t *testing.T) {
174+
t.Parallel()
159175
xs := []string{"Christopher", "Llewellyn"}
160176
VerifyAll(t, "uppercase", xs, func(x interface{}) string { return fmt.Sprintf("%s => %s", x, strings.ToUpper(x.(string))) })
161177
}
162178

163179
func TestVerifyAllCombinationsFor1(t *testing.T) {
180+
t.Parallel()
164181
xs := []string{"Christopher", "Llewellyn"}
165182
VerifyAllCombinationsFor1(t, "uppercase", func(x interface{}) string { return strings.ToUpper(x.(string)) }, xs)
166183
}
167184

168185
func TestVerifyAllCombinationsForSkipped(t *testing.T) {
186+
t.Parallel()
169187
xs := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
170188
VerifyAllCombinationsFor1(
171189
t,
@@ -180,6 +198,7 @@ func TestVerifyAllCombinationsForSkipped(t *testing.T) {
180198
}
181199

182200
func TestVerifyAllCombinationsFor2(t *testing.T) {
201+
t.Parallel()
183202
xs1 := []string{"Christopher", "Llewellyn"}
184203
xs2 := []int{0, 1}
185204
VerifyAllCombinationsFor2(
@@ -191,6 +210,7 @@ func TestVerifyAllCombinationsFor2(t *testing.T) {
191210
}
192211

193212
func TestVerifyAllCombinationsFor9(t *testing.T) {
213+
t.Parallel()
194214
xs1 := []string{"Christopher"}
195215

196216
VerifyAllCombinationsFor9(

documentation_examples/documentation_examples_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88

99
// begin-snippet: hello_world
1010
func TestHelloWorld(t *testing.T) {
11+
t.Parallel()
1112
approvals.VerifyString(t, "Hello World!")
1213
}
1314

1415
// end-snippet
1516

1617
// begin-snippet: verify_json
1718
func TestVerifyJSON(t *testing.T) {
19+
t.Parallel()
1820
jsonb := []byte("{ \"foo\": \"bar\", \"age\": 42, \"bark\": \"woof\" }")
1921
approvals.VerifyJSONBytes(t, jsonb)
2022
}

examples_helper_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
var (
1414
// this is a mock testing.T for documentation purposes
15-
t = &approvals.TestFailable{}
15+
t = approvals.NewTestFailableWithName("TestExampleForDocumentation")
1616
)
1717

1818
// failing is a mock struct that is only there for documentation convenience,

reporter_test.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ func (s *TestFailable) Name() string {
2121

2222
}
2323
func (s *TestFailable) Error(args ...interface{}) {
24-
fmt.Println("This test failed")
24+
fmt.Printf("%s failed (expected)\n", s.Name())
2525
}
2626
func (s *TestFailable) Helper() {}
2727

28-
func NewTestFailable() *TestFailable {
29-
return &TestFailable{
30-
name: "TestFailable",
31-
}
32-
}
3328
func NewTestFailableWithName(name string) *TestFailable {
3429
return &TestFailable{
3530
name: name,
@@ -56,14 +51,15 @@ func (s *testReporter) Report(approved, received string) bool {
5651
}
5752

5853
func TestUseReporter(t *testing.T) {
54+
t.Parallel()
5955
front := UseFrontLoadedReporter(newTestReporter(false))
6056
defer front.Close()
6157

6258
old := getReporter()
6359
a := newTestReporter(true)
6460
r := UseReporter(reporters.Reporter(a))
6561

66-
f := &TestFailable{}
62+
f := NewTestFailableWithName(t.Name())
6763

6864
VerifyString(f, "foo")
6965

@@ -79,6 +75,7 @@ func TestUseReporter(t *testing.T) {
7975
}
8076

8177
func TestFrontLoadedReporter(t *testing.T) {
78+
t.Parallel()
8279
old := getReporter()
8380
front := newTestReporter(false)
8481
next := newTestReporter(true)
@@ -87,7 +84,7 @@ func TestFrontLoadedReporter(t *testing.T) {
8784
nextCloser := UseReporter(reporters.Reporter(next))
8885
defer nextCloser.Close()
8986

90-
f := &TestFailable{}
87+
f := NewTestFailableWithName(t.Name())
9188

9289
VerifyString(f, "foo")
9390

reporters/reporter_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (s *testReporter) Report(approved, received string) bool {
2626
}
2727

2828
func TestFirstWorkingReporter(t *testing.T) {
29+
t.Parallel()
2930
a := newTestReporter(false)
3031
b := newTestReporter(true)
3132
c := newTestReporter(true)
@@ -39,6 +40,7 @@ func TestFirstWorkingReporter(t *testing.T) {
3940
}
4041

4142
func TestMultiReporter(t *testing.T) {
43+
t.Parallel()
4244
a := newTestReporter(true)
4345
b := newTestReporter(true)
4446

@@ -51,6 +53,7 @@ func TestMultiReporter(t *testing.T) {
5153
}
5254

5355
func TestMultiReporterWithNoWorkingReporters(t *testing.T) {
56+
t.Parallel()
5457
a := newTestReporter(false)
5558
b := newTestReporter(false)
5659

@@ -71,6 +74,7 @@ func restoreEnv(exists bool, key, value string) {
7174
}
7275

7376
func TestCIReporter(t *testing.T) {
77+
t.Parallel()
7478
value, exists := os.LookupEnv("CI")
7579

7680
os.Setenv("CI", "true")

scrubber_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestVerifyDoesNotAcceptSeveralVerifyOptions(t *testing.T) {
14+
t.Parallel()
1415
scrubber1, _ := regexp.Compile("\\d{10}$")
1516
opts1 := approvals.Options().WithRegexScrubber(scrubber1, "<time>")
1617
opts2 := approvals.Options().WithRegexScrubber(scrubber1, "<time>")
@@ -24,6 +25,7 @@ func TestVerifyDoesNotAcceptSeveralVerifyOptions(t *testing.T) {
2425
}
2526

2627
func TestVerifyMapWithRegexScrubber(t *testing.T) {
28+
t.Parallel()
2729
scrubber, _ := regexp.Compile("\\d{10}$")
2830
opts := approvals.Options().WithRegexScrubber(scrubber, "<time>")
2931

@@ -36,6 +38,7 @@ func TestVerifyMapWithRegexScrubber(t *testing.T) {
3638
}
3739

3840
func TestVerifyArrayWithRegexScrubber(t *testing.T) {
41+
t.Parallel()
3942
scrubber, _ := regexp.Compile("cat")
4043
opts := approvals.Options().WithRegexScrubber(scrubber, "person")
4144

@@ -44,6 +47,7 @@ func TestVerifyArrayWithRegexScrubber(t *testing.T) {
4447
}
4548

4649
func TestVerifyJSONBytesWithRegexScrubber(t *testing.T) {
50+
t.Parallel()
4751
scrubber, _ := regexp.Compile("Hello")
4852
opts := approvals.Options().WithRegexScrubber(scrubber, "Hi")
4953

@@ -52,6 +56,7 @@ func TestVerifyJSONBytesWithRegexScrubber(t *testing.T) {
5256
}
5357

5458
func TestVerifyXMLBytesWithRegexScrubber(t *testing.T) {
59+
t.Parallel()
5560
scrubber, _ := regexp.Compile("Hello")
5661
opts := approvals.Options().WithRegexScrubber(scrubber, "Hi")
5762

@@ -60,6 +65,7 @@ func TestVerifyXMLBytesWithRegexScrubber(t *testing.T) {
6065
}
6166

6267
func TestVerifyStringWithRegexScrubber(t *testing.T) {
68+
t.Parallel()
6369
scrubber, _ := regexp.Compile("\\d{10}$")
6470
opts := approvals.Options().WithRegexScrubber(scrubber, "<now>")
6571

@@ -68,6 +74,7 @@ func TestVerifyStringWithRegexScrubber(t *testing.T) {
6874
}
6975

7076
func TestVerifyStringWithMultipleScrubbers(t *testing.T) {
77+
t.Parallel()
7178
scrubber1, _ := regexp.Compile("\\d{10}$")
7279
scrubber2, _ := regexp.Compile("time")
7380

@@ -80,6 +87,7 @@ func TestVerifyStringWithMultipleScrubbers(t *testing.T) {
8087
}
8188

8289
func TestVerifyAllWithRegexScrubber(t *testing.T) {
90+
t.Parallel()
8391
scrubber, _ := regexp.Compile("Llewellyn")
8492
opts := approvals.Options().WithRegexScrubber(scrubber, "Walken")
8593

@@ -88,6 +96,7 @@ func TestVerifyAllWithRegexScrubber(t *testing.T) {
8896
}
8997

9098
func TestScrubGuids(t *testing.T) {
99+
t.Parallel()
91100
guids := []string{"2fd78d4a-ad49-447d-96a8-deda585a9aa5",
92101
"2fd78d4a-1111-1111-1111-deda585a9aa5",
93102
"2fd78d4a-3333-3333-3333-deda585a9aa5",

templated_custom_namer_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
)
77

88
func Test00(t *testing.T) {
9+
t.Parallel()
910
namer := getApprovalNameCreator()(t)
1011

1112
approvalFile := namer.GetApprovalFile(".txt")
@@ -22,6 +23,7 @@ func assertEndsWith(s string, ending string, t *testing.T) {
2223
}
2324

2425
func TestTemplatedCustomNamer(t *testing.T) {
26+
t.Parallel()
2527
custom := CreateTemplatedCustomNamerCreator("{TestSourceDirectory}/{ApprovalsSubdirectory}/{TestFileName}.{TestCaseName}.custom.{ApprovedOrReceived}.{FileExtension}")
2628
VerifyString(t, "Hello", Options().ForFile().WithNamer(custom))
2729
}

0 commit comments

Comments
 (0)