Skip to content

Commit b212cf9

Browse files
authored
Mongo codec: test more carefully around the float limit boundary (#3348)
Really a nit but for the complete peace of mind
1 parent 9667072 commit b212cf9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

flow/connectors/mongo/codec_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,23 @@ func TestMarshalFloatLengths(t *testing.T) {
374374
})
375375
}
376376
}
377+
378+
// Test the boundary around the limit itself
379+
for _, value := range []float64{
380+
floatLimit, math.Nextafter(floatLimit, math.Inf(1)), math.Nextafter(floatLimit, math.Inf(-1)),
381+
floatNegLimit, math.Nextafter(floatNegLimit, math.Inf(1)), math.Nextafter(floatNegLimit, math.Inf(-1)),
382+
} {
383+
name := fmt.Sprint(value)
384+
t.Run(name, func(t *testing.T) {
385+
input := bson.D{{Key: "a", Value: value}}
386+
result, err := API.Marshal(input)
387+
require.NoError(t, err)
388+
resultStr := string(result)
389+
require.Less(t, len(resultStr), 33)
390+
require.True(t,
391+
strings.Contains(resultStr, ".") ||
392+
strings.Contains(resultStr, "e"),
393+
resultStr)
394+
})
395+
}
377396
}

0 commit comments

Comments
 (0)