Skip to content

Commit

Permalink
rewrite comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleader committed Jan 26, 2024
1 parent fdb4953 commit 8509ca2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
7 changes: 4 additions & 3 deletions schema/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 11 additions & 6 deletions schema/units_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
7 changes: 4 additions & 3 deletions schema/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8509ca2

Please sign in to comment.