From 8509ca28ff46c0c6954f7e181d9a3e01897943df Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Fri, 26 Jan 2024 16:54:49 -0500 Subject: [PATCH] rewrite comment --- schema/bool_test.go | 7 ++++--- schema/units_test.go | 17 +++++++++++------ schema/util_test.go | 7 ++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/schema/bool_test.go b/schema/bool_test.go index 046f6de..146f1d7 100644 --- a/schema/bool_test.go +++ b/schema/bool_test.go @@ -151,10 +151,11 @@ var boolTestSerializationCases = map[string]struct { } func TestBoolSerializationCycle(t *testing.T) { + t.Parallel() for name, tc := range boolTestSerializationCases { - // The call to t.Parallel() means that referencing the tc - // from the outer scope won't produce the proper value, so - // we need to place it in a variable, localTC, scoped inside + // When executed in parallel, referencing tc from the + // outer scope will not produce the proper value, so we need + // to bind it to a variable, localTC, scoped inside // the loop body. localTC := tc t.Run(name, func(t *testing.T) { diff --git a/schema/units_test.go b/schema/units_test.go index 51f3bd1..2d64cf5 100644 --- a/schema/units_test.go +++ b/schema/units_test.go @@ -35,17 +35,22 @@ func TestUnitsParseInt(t *testing.T) { } for testCase, testData := range testMatrix { + // When executed in parallel, referencing testData from the + // outer scope will not produce the proper value, so we need + // to bind it to a variable, localTestData, scoped inside + // the loop body. + localTestData := testData t.Run(testCase, func(t *testing.T) { - result, err := testData.units.ParseInt(testData.input) + result, err := localTestData.units.ParseInt(localTestData.input) if err != nil { t.Fatal(err) } - if result != testData.expected { - t.Fatalf("Result mismatch, expected: %d, got: %d", testData.expected, result) + if result != localTestData.expected { + t.Fatalf("Result mismatch, expected: %d, got: %d", localTestData.expected, result) } - formatted := testData.units.FormatShortInt(result) - if formatted != testData.input { - t.Fatalf("Formatted result doesn't match input, expected: %s, got: %s", testData.input, formatted) + formatted := localTestData.units.FormatShortInt(result) + if formatted != localTestData.input { + t.Fatalf("Formatted result doesn't match input, expected: %s, got: %s", localTestData.input, formatted) } }) } diff --git a/schema/util_test.go b/schema/util_test.go index d74140e..06e78b7 100644 --- a/schema/util_test.go +++ b/schema/util_test.go @@ -21,10 +21,11 @@ func performSerializationTest[T any]( compareSerialized func(a any, b any) bool, ) { t.Helper() + t.Parallel() for name, tc := range testCases { - // The call to t.Parallel() means that referencing the tc - // from the outer scope won't produce the proper value, so - // we need to place it in a variable, localTC, scoped inside + // When executed in parallel, referencing tc from the + // outer scope will not produce the proper value, so we need + // to bind it to a variable, localTC, scoped inside // the loop body. localTC := tc t.Run(name, func(t *testing.T) {