Skip to content

Commit f9a0d4b

Browse files
committed
Fix
1 parent a5cc01d commit f9a0d4b

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

tools/flakeguard/go-test-transform/pkg/transformer/transformer_test.go

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func createEvent(action, pkg, test string, elapsed float64, output string) testE
2626
}
2727

2828
// transformAndVerify is a helper function to transform events and verify the results
29-
func transformAndVerify(t *testing.T, events []testEvent, opts *Options, expectedExitCode int, expectedActions map[string]string) {
29+
func transformAndVerify(t *testing.T, events []testEvent, opts *Options, expectedActions map[string]string) {
3030
// Convert test events to JSON
3131
var input bytes.Buffer
3232
for _, event := range events {
@@ -39,16 +39,11 @@ func transformAndVerify(t *testing.T, events []testEvent, opts *Options, expecte
3939

4040
// Transform the events
4141
var output bytes.Buffer
42-
exitCode, err := TransformJSON(&input, &output, opts)
42+
err := TransformJSON(&input, &output, opts)
4343
if err != nil {
4444
t.Fatalf("Failed to transform JSON: %v", err)
4545
}
4646

47-
// Verify exit code
48-
if exitCode != expectedExitCode {
49-
t.Errorf("Expected exit code %d, got %d", expectedExitCode, exitCode)
50-
}
51-
5247
// Parse the output
5348
scanner := bufio.NewScanner(&output)
5449
var resultEvents []TestEvent
@@ -105,7 +100,7 @@ func TestIgnoreAllSubtests(t *testing.T) {
105100
"example/": "pass",
106101
}
107102

108-
transformAndVerify(t, events, opts, 1, expectedActions)
103+
transformAndVerify(t, events, opts, expectedActions)
109104
}
110105

111106
// TestNestedSubtests tests handling nested subtests
@@ -139,7 +134,7 @@ func TestNestedSubtests(t *testing.T) {
139134
"example/": "pass",
140135
}
141136

142-
transformAndVerify(t, events, opts, 1, expectedActions)
137+
transformAndVerify(t, events, opts, expectedActions)
143138
}
144139

145140
// TestParallelTestsEventOrdering tests handling of parallel tests
@@ -171,7 +166,7 @@ func TestParallelTestsEventOrdering(t *testing.T) {
171166
"example/": "pass",
172167
}
173168

174-
transformAndVerify(t, events, opts, 1, expectedActions)
169+
transformAndVerify(t, events, opts, expectedActions)
175170
}
176171

177172
// TestOutputTransformation tests transformation of output text
@@ -191,16 +186,12 @@ func TestEmptyInput(t *testing.T) {
191186
opts := DefaultOptions()
192187

193188
var input, output bytes.Buffer
194-
exitCode, err := TransformJSON(&input, &output, opts)
189+
err := TransformJSON(&input, &output, opts)
195190

196191
if err != nil {
197192
t.Errorf("Expected no error for empty input, got: %v", err)
198193
}
199194

200-
if exitCode != 0 {
201-
t.Errorf("Expected exit code 0 for empty input, got: %d", exitCode)
202-
}
203-
204195
if output.Len() != 0 {
205196
t.Errorf("Expected empty output for empty input, got: %s", output.String())
206197
}
@@ -213,7 +204,7 @@ func TestMalformedJSON(t *testing.T) {
213204
input := strings.NewReader("This is not JSON\n{\"Action\":\"fail\"")
214205
var output bytes.Buffer
215206

216-
_, err := TransformJSON(input, &output, opts)
207+
err := TransformJSON(input, &output, opts)
217208

218209
if err == nil {
219210
t.Error("Expected error for malformed JSON, got nil")
@@ -257,7 +248,7 @@ func TestParentWithDirectFailureAndFailingSubtest(t *testing.T) {
257248
"example/": "pass",
258249
}
259250

260-
transformAndVerify(t, events, opts, 1, expectedActions)
251+
transformAndVerify(t, events, opts, expectedActions)
261252
}
262253

263254
func TestParentWithOnlyDirectFailure(t *testing.T) {
@@ -290,7 +281,7 @@ func TestParentWithOnlyDirectFailure(t *testing.T) {
290281
"example/": "pass",
291282
}
292283

293-
transformAndVerify(t, events, opts, 1, expectedActions)
284+
transformAndVerify(t, events, opts, expectedActions)
294285
}
295286

296287
// TestMultiLevelNestedFailures tests multiple levels of nested failures
@@ -333,7 +324,7 @@ func TestMultiLevelNestedFailures(t *testing.T) {
333324
"example/": "pass",
334325
}
335326

336-
transformAndVerify(t, events, opts, 1, expectedActions)
327+
transformAndVerify(t, events, opts, expectedActions)
337328
}
338329

339330
// TestOnlyDirectFailures tests a scenario where there are no failing subtests, only direct failures
@@ -377,7 +368,7 @@ func TestOnlyDirectFailures(t *testing.T) {
377368
}
378369

379370
// Exit code should be 1 because there are still failing tests
380-
transformAndVerify(t, events, opts, 1, expectedActions)
371+
transformAndVerify(t, events, opts, expectedActions)
381372
}
382373

383374
// TestLogMessagesNotDirectFailures tests that log messages are not treated as direct failures
@@ -417,7 +408,7 @@ func TestLogMessagesNotDirectFailures(t *testing.T) {
417408
"example/": "pass",
418409
}
419410

420-
transformAndVerify(t, events, opts, 1, expectedActions)
411+
transformAndVerify(t, events, opts, expectedActions)
421412
}
422413

423414
// TestNestedLogsAllPassing tests that log messages in passing tests are handled correctly
@@ -453,7 +444,7 @@ func TestNestedLogsAllPassing(t *testing.T) {
453444
"example/": "pass",
454445
}
455446

456-
transformAndVerify(t, events, opts, 0, expectedActions)
447+
transformAndVerify(t, events, opts, expectedActions)
457448
}
458449

459450
// TestSkippedTests tests handling of skipped tests
@@ -483,7 +474,7 @@ func TestSkippedTests(t *testing.T) {
483474
"example/TestSkippedTests": "pass",
484475
}
485476

486-
transformAndVerify(t, events, opts, 0, expectedActions)
477+
transformAndVerify(t, events, opts, expectedActions)
487478
}
488479

489480
// TestDeepNesting tests handling of deeply nested test hierarchies
@@ -529,7 +520,7 @@ func TestDeepNesting(t *testing.T) {
529520
"example/": "pass",
530521
}
531522

532-
transformAndVerify(t, events, opts, 1, expectedActions)
523+
transformAndVerify(t, events, opts, expectedActions)
533524
}
534525

535526
// TestConcurrentTests tests handling of concurrent test execution
@@ -580,7 +571,7 @@ func TestConcurrentTests(t *testing.T) {
580571
"example/": "pass",
581572
}
582573

583-
transformAndVerify(t, events, opts, 1, expectedActions)
574+
transformAndVerify(t, events, opts, expectedActions)
584575
}
585576

586577
// TestTableDrivenTests tests handling of table-driven tests
@@ -628,7 +619,7 @@ func TestTableDrivenTests(t *testing.T) {
628619
"example/": "pass",
629620
}
630621

631-
transformAndVerify(t, events, opts, 1, expectedActions)
622+
transformAndVerify(t, events, opts, expectedActions)
632623
}
633624

634625
// TestSubtestReuse tests handling of tests that reuse the same subtest function
@@ -677,7 +668,7 @@ func TestSubtestReuse(t *testing.T) {
677668
"example/": "pass",
678669
}
679670

680-
transformAndVerify(t, events, opts, 1, expectedActions)
671+
transformAndVerify(t, events, opts, expectedActions)
681672
}
682673

683674
// TestSpecialCharactersInTestNames tests handling of tests with special characters in names
@@ -720,7 +711,7 @@ func TestSpecialCharactersInTestNames(t *testing.T) {
720711
"example/": "pass",
721712
}
722713

723-
transformAndVerify(t, events, opts, 1, expectedActions)
714+
transformAndVerify(t, events, opts, expectedActions)
724715
}
725716

726717
func TestSubTestNameWithSlashes(t *testing.T) {
@@ -751,7 +742,7 @@ func TestSubTestNameWithSlashes(t *testing.T) {
751742
"example/": "pass",
752743
}
753744

754-
transformAndVerify(t, events, opts, 0, expectedActions)
745+
transformAndVerify(t, events, opts, expectedActions)
755746
}
756747

757748
func TestFuzzTestWithCorpus(t *testing.T) {
@@ -796,5 +787,5 @@ func TestFuzzTestWithCorpus(t *testing.T) {
796787
}
797788

798789
// transformAndVerify should yield exit code 0 since everything passes
799-
transformAndVerify(t, events, opts, 0, expectedActions)
790+
transformAndVerify(t, events, opts, expectedActions)
800791
}

0 commit comments

Comments
 (0)