Skip to content

Commit 7381606

Browse files
authored
GODRIVER-2433 add tests for Decimal-128 (#1159)
* add decimal128 to explicit tests * add fle2-Range-Decimal* spec tests * use libmongocrypt 1.7.0-alpha2 in tests
1 parent de9108a commit 7381606

28 files changed

+24473
-4
lines changed

.evergreen/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ functions:
3636
params:
3737
working_dir: src/go.mongodb.org/mongo-driver
3838
script: |
39+
set -o errexit
40+
3941
# Get the current unique version of this checkout.
4042
if [ "${is_patch}" = "true" ]; then
4143
CURRENT_VERSION=$(git describe)-patch-${version_id}
@@ -94,7 +96,7 @@ functions:
9496
go env
9597
9698
# TODO(GODRIVER-2676): use libmongocrypt 1.7.0 once it is released.
97-
LIBMONGOCRYPT_TAG="1.7.0-alpha1"
99+
LIBMONGOCRYPT_TAG="1.7.0-alpha2"
98100
# Install libmongocrypt based on OS.
99101
if [ "Windows_NT" = "$OS" ]; then
100102
mkdir -p c:/libmongocrypt/include
@@ -106,7 +108,7 @@ functions:
106108
# TODO(GODRIVER-2676): replace this URL once libmongocrypt 1.7.0 is released with the following:
107109
# curl https://mciuploads.s3.amazonaws.com/libmongocrypt/all/$LIBMONGOCRYPT_TAG/libmongocrypt-all.tar.gz -o libmongocrypt-all.tar.gz
108110
# There is no tag URL for libmongocrypt pre-releases.
109-
LIBMONGOCRYPT_COMMIT=2cd2f77ae806a3a4c12750b39b0be92b0ca3b2c1
111+
LIBMONGOCRYPT_COMMIT=1a28503fed3dbf7bf4cde649debb750666d72c4c
110112
curl https://mciuploads.s3.amazonaws.com/libmongocrypt/all/master/$LIBMONGOCRYPT_COMMIT/libmongocrypt-all.tar.gz -o libmongocrypt-all.tar.gz
111113
tar -xf libmongocrypt-all.tar.gz
112114
cd ..

mongo/integration/client_side_encryption_prose_test.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,47 @@ func TestClientSideEncryptionProse(t *testing.T) {
22122212

22132213
precision := int32(2)
22142214

2215+
d128_0, err := primitive.ParseDecimal128("0")
2216+
assert.Nil(mt, err)
2217+
d128_6, err := primitive.ParseDecimal128("6")
2218+
assert.Nil(mt, err)
2219+
d128_30, err := primitive.ParseDecimal128("30")
2220+
assert.Nil(mt, err)
2221+
d128_200, err := primitive.ParseDecimal128("200")
2222+
assert.Nil(mt, err)
2223+
d128_201, err := primitive.ParseDecimal128("201")
2224+
assert.Nil(mt, err)
2225+
22152226
tests := []testcase{
2227+
{
2228+
typeStr: "DecimalNoPrecision",
2229+
field: "encryptedDecimalNoPrecision",
2230+
typeBson: bson.TypeDecimal128,
2231+
rangeOpts: options.RangeOptions{
2232+
Sparsity: 1,
2233+
},
2234+
zero: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_0)},
2235+
six: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_6)},
2236+
thirty: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_30)},
2237+
twoHundred: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_200)},
2238+
twoHundredOne: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_201)},
2239+
},
2240+
{
2241+
typeStr: "DecimalPrecision",
2242+
field: "encryptedDecimalPrecision",
2243+
typeBson: bson.TypeDecimal128,
2244+
rangeOpts: options.RangeOptions{
2245+
Min: &bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_0)},
2246+
Max: &bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_200)},
2247+
Sparsity: 1,
2248+
Precision: &precision,
2249+
},
2250+
zero: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_0)},
2251+
six: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_6)},
2252+
thirty: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_30)},
2253+
twoHundred: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_200)},
2254+
twoHundredOne: bson.RawValue{Type: bson.TypeDecimal128, Value: bsoncore.AppendDecimal128(nil, d128_201)},
2255+
},
22162256
{
22172257
typeStr: "DoubleNoPrecision",
22182258
field: "encryptedDoubleNoPrecision",
@@ -2291,6 +2331,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
22912331

22922332
for _, test := range tests {
22932333
mt.Run(test.typeStr, func(mt *mtest.T) {
2334+
if test.typeStr == "DecimalNoPrecision" && mtest.ClusterTopologyKind() != mtest.ReplicaSet {
2335+
mt.Skipf("Skipping DecimalNoPrecision tests on a non ReplicaSet topology. DecimalNoPrecision queries are expected to take a long time and may exceed the default mongos timeout")
2336+
}
2337+
22942338
// Test Setup ... begin
22952339
encryptedFields := readJSONFile(mt, fmt.Sprintf("range-encryptedFields-%v.json", test.typeStr))
22962340
key1Document := readJSONFile(mt, "key1-document.json")
@@ -2548,7 +2592,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
25482592
checkCursorResults(cursor, test.field, test.zero, test.six)
25492593
})
25502594

2551-
if test.field != "encryptedDoubleNoPrecision" {
2595+
if test.field != "encryptedDoubleNoPrecision" && test.field != "encryptedDecimalNoPrecision" {
25522596
mt.Run("Case 6: encrypting a document greater than the maximum errors", func(mt *mtest.T) {
25532597
encryptedClient, clientEncryption := testSetup()
25542598
defer clientEncryption.Close(context.Background())
@@ -2585,7 +2629,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
25852629
})
25862630
}
25872631

2588-
if test.field != "encryptedDoubleNoPrecision" && test.field != "encryptedDoublePrecision" {
2632+
if test.field != "encryptedDoubleNoPrecision" && test.field != "encryptedDoublePrecision" && test.field != "encryptedDecimalNoPrecision" && test.field != "encryptedDecimalPrecision" {
25892633
mt.Run("Case 8: setting precision errors if the type is not a double", func(mt *mtest.T) {
25902634
encryptedClient, clientEncryption := testSetup()
25912635
defer clientEncryption.Close(context.Background())
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDecimalNoPrecision",
11+
"bsonType": "decimal",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberInt": "1"
16+
}
17+
}
18+
}
19+
]
20+
}
21+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDecimalPrecision",
11+
"bsonType": "decimal",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberInt": "1"
16+
},
17+
"min": {
18+
"$numberDecimal": "0.0"
19+
},
20+
"max": {
21+
"$numberDecimal": "200.0"
22+
},
23+
"precision": {
24+
"$numberInt": "2"
25+
}
26+
}
27+
}
28+
]
29+
}

0 commit comments

Comments
 (0)