From a7e9f3ee283288fe633320dd402f6fa698cb7dc1 Mon Sep 17 00:00:00 2001
From: Guillem Jover <gjover@sipwise.com>
Date: Mon, 13 Dec 2021 20:12:33 +0100
Subject: [PATCH] Fix test suite using 64-bit literals on 32-bit systems
Forwarded: https://github.com/mongodb/mongo-go-driver/pull/826

The literals do not fit in those int types on 32-bit systems, so
we either need to use 64-bit types, or remove the test case when
it is redundant with an actual 64-bit case.

Signed-off-by: Guillem Jover <gjover@sipwise.com>
---
 bson/bsoncodec/default_value_decoders_test.go | 12 ++++++------
 bson/bsoncodec/default_value_encoders_test.go | 11 ++---------
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/bson/bsoncodec/default_value_decoders_test.go b/bson/bsoncodec/default_value_decoders_test.go
index 3c29cc99..0cd41aab 100644
--- a/bson/bsoncodec/default_value_decoders_test.go
+++ b/bson/bsoncodec/default_value_decoders_test.go
@@ -274,7 +274,7 @@ func TestDefaultValueDecoders(t *testing.T) {
 				{
 					"int32/fast path - overflow", int32(0), nil,
 					&bsonrwtest.ValueReaderWriter{BSONType: bsontype.Int64, Return: int64(2147483648)}, bsonrwtest.ReadInt64,
-					fmt.Errorf("%d overflows int32", 2147483648),
+					fmt.Errorf("%d overflows int32", int64(2147483648)),
 				},
 				{
 					"int8/fast path - overflow (negative)", int8(0), nil,
@@ -289,7 +289,7 @@ func TestDefaultValueDecoders(t *testing.T) {
 				{
 					"int32/fast path - overflow (negative)", int32(0), nil,
 					&bsonrwtest.ValueReaderWriter{BSONType: bsontype.Int64, Return: int64(-2147483649)}, bsonrwtest.ReadInt64,
-					fmt.Errorf("%d overflows int32", -2147483649),
+					fmt.Errorf("%d overflows int32", int64(-2147483649)),
 				},
 				{
 					"int8/reflection path", myint8(127), nil,
@@ -329,7 +329,7 @@ func TestDefaultValueDecoders(t *testing.T) {
 				{
 					"int32/reflection path - overflow", myint32(0), nil,
 					&bsonrwtest.ValueReaderWriter{BSONType: bsontype.Int64, Return: int64(2147483648)}, bsonrwtest.ReadInt64,
-					fmt.Errorf("%d overflows int32", 2147483648),
+					fmt.Errorf("%d overflows int32", int64(2147483648)),
 				},
 				{
 					"int8/reflection path - overflow (negative)", myint8(0), nil,
@@ -344,7 +344,7 @@ func TestDefaultValueDecoders(t *testing.T) {
 				{
 					"int32/reflection path - overflow (negative)", myint32(0), nil,
 					&bsonrwtest.ValueReaderWriter{BSONType: bsontype.Int64, Return: int64(-2147483649)}, bsonrwtest.ReadInt64,
-					fmt.Errorf("%d overflows int32", -2147483649),
+					fmt.Errorf("%d overflows int32", int64(-2147483649)),
 				},
 				{
 					"can set false",
@@ -506,7 +506,7 @@ func TestDefaultValueDecoders(t *testing.T) {
 				{
 					"uint32/fast path - overflow", uint32(0), nil,
 					&bsonrwtest.ValueReaderWriter{BSONType: bsontype.Int64, Return: int64(1 << 32)}, bsonrwtest.ReadInt64,
-					fmt.Errorf("%d overflows uint32", 1<<32),
+					fmt.Errorf("%d overflows uint32", int64(1<<32)),
 				},
 				{
 					"uint8/fast path - overflow (negative)", uint8(0), nil,
@@ -571,7 +571,7 @@ func TestDefaultValueDecoders(t *testing.T) {
 				{
 					"uint32/reflection path - overflow", myuint32(0), nil,
 					&bsonrwtest.ValueReaderWriter{BSONType: bsontype.Int64, Return: int64(1 << 32)}, bsonrwtest.ReadInt64,
-					fmt.Errorf("%d overflows uint32", 1<<32),
+					fmt.Errorf("%d overflows uint32", int64(1<<32)),
 				},
 				{
 					"uint8/reflection path - overflow (negative)", myuint8(0), nil,
diff --git a/bson/bsoncodec/default_value_encoders_test.go b/bson/bsoncodec/default_value_encoders_test.go
index 52ab079c..0cb35a1a 100644
--- a/bson/bsoncodec/default_value_encoders_test.go
+++ b/bson/bsoncodec/default_value_encoders_test.go
@@ -124,8 +124,6 @@ func TestDefaultValueEncoders(t *testing.T) {
 				{"int/fast path - negative int32", int(math.MinInt32 + 1), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"int/fast path - MaxInt32", int(math.MaxInt32), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"int/fast path - MinInt32", int(math.MinInt32), nil, nil, bsonrwtest.WriteInt32, nil},
-				{"int/fast path - larger than MaxInt32", int(math.MaxInt32 + 1), nil, nil, bsonrwtest.WriteInt64, nil},
-				{"int/fast path - smaller than MinInt32", int(math.MinInt32 - 1), nil, nil, bsonrwtest.WriteInt64, nil},
 				{"int8/reflection path", myint8(127), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"int16/reflection path", myint16(32767), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"int32/reflection path", myint32(2147483647), nil, nil, bsonrwtest.WriteInt32, nil},
@@ -137,8 +135,6 @@ func TestDefaultValueEncoders(t *testing.T) {
 				{"int/reflection path - negative int32", myint(math.MinInt32 + 1), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"int/reflection path - MaxInt32", myint(math.MaxInt32), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"int/reflection path - MinInt32", myint(math.MinInt32), nil, nil, bsonrwtest.WriteInt32, nil},
-				{"int/reflection path - larger than MaxInt32", myint(math.MaxInt32 + 1), nil, nil, bsonrwtest.WriteInt64, nil},
-				{"int/reflection path - smaller than MinInt32", myint(math.MinInt32 - 1), nil, nil, bsonrwtest.WriteInt64, nil},
 			},
 		},
 		{
@@ -168,21 +164,18 @@ func TestDefaultValueEncoders(t *testing.T) {
 				{"uint32/fast path - minsize too large", uint32(2147483648), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt64, nil},
 				{"uint64/fast path - minsize too large", uint64(2147483648), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt64, nil},
 				{"uint/fast path - minsize too large", uint(2147483648), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt64, nil},
-				{"uint64/fast path - overflow", uint64(1 << 63), nil, nil, bsonrwtest.Nothing, fmt.Errorf("%d overflows int64", uint(1<<63))},
-				{"uint/fast path - overflow", uint(1 << 63), nil, nil, bsonrwtest.Nothing, fmt.Errorf("%d overflows int64", uint(1<<63))},
+				{"uint64/fast path - overflow", uint64(1 << 63), nil, nil, bsonrwtest.Nothing, fmt.Errorf("%d overflows int64", uint64(1<<63))},
 				{"uint8/reflection path", myuint8(127), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"uint16/reflection path", myuint16(32767), nil, nil, bsonrwtest.WriteInt32, nil},
 				{"uint32/reflection path", myuint32(2147483647), nil, nil, bsonrwtest.WriteInt64, nil},
 				{"uint64/reflection path", myuint64(1234567890987), nil, nil, bsonrwtest.WriteInt64, nil},
-				{"uint/reflection path", myuint(1234567890987), nil, nil, bsonrwtest.WriteInt64, nil},
 				{"uint32/reflection path - minsize", myuint32(2147483647), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt32, nil},
 				{"uint64/reflection path - minsize", myuint64(2147483647), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt32, nil},
 				{"uint/reflection path - minsize", myuint(2147483647), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt32, nil},
 				{"uint32/reflection path - minsize too large", myuint(1 << 31), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt64, nil},
 				{"uint64/reflection path - minsize too large", myuint64(1 << 31), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt64, nil},
 				{"uint/reflection path - minsize too large", myuint(2147483648), &EncodeContext{MinSize: true}, nil, bsonrwtest.WriteInt64, nil},
-				{"uint64/reflection path - overflow", myuint64(1 << 63), nil, nil, bsonrwtest.Nothing, fmt.Errorf("%d overflows int64", uint(1<<63))},
-				{"uint/reflection path - overflow", myuint(1 << 63), nil, nil, bsonrwtest.Nothing, fmt.Errorf("%d overflows int64", uint(1<<63))},
+				{"uint64/reflection path - overflow", myuint64(1 << 63), nil, nil, bsonrwtest.Nothing, fmt.Errorf("%d overflows int64", uint64(1<<63))},
 			},
 		},
 		{
-- 
2.34.1

