Skip to content

Commit ffc1b65

Browse files
committed
convert values to float64 for comparison
1 parent a45b827 commit ffc1b65

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

internal/integration/unified/matches.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,22 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua
251251

252252
// Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual
253253
// is an int64).
254-
expectedInt64 := assertionVal.AsInt64()
255-
actualInt64 := actual.AsInt64()
256-
if actualInt64 > expectedInt64 {
257-
return fmt.Errorf("expected numeric value %d to be less than or equal %d", actualInt64, expectedInt64)
254+
var expectedF64 float64
255+
if assertionVal.Type == bson.TypeDouble {
256+
expectedF64 = assertionVal.Double()
257+
} else {
258+
expectedF64 = float64(assertionVal.AsInt64())
259+
}
260+
261+
var actualF64 float64
262+
if actual.Type == bson.TypeDouble {
263+
actualF64 = actual.Double()
264+
} else {
265+
actualF64 = float64(actual.AsInt64())
266+
}
267+
268+
if actualF64 > expectedF64 {
269+
return fmt.Errorf("expected numeric value %f to be less than or equal %f", actualF64, expectedF64)
258270
}
259271
return nil
260272
case "$$matchAsDocument":

0 commit comments

Comments
 (0)