Files
docdb/integration/query_element_compat_test.go
zeekayandHanzo Dev 06d5eca873 Declare operations on the group that serves them
zip's registration is a verb method on the group, so an operation reads as the
group answering it rather than a function taking the group, and a route that is
not a typed operation says which method it answers with. The package-level form
and the Router interface it existed to accept any target through are both gone.

The toolchain and the pin move together, deliberately. Below zip v1.36.50 the
JSON encoder was selected on a build tag, so a repo whose go directive rises
first writes a wire that is neither the old release's nor the new one's until the
pin catches up.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 06:11:42 -07:00

147 lines
4.0 KiB
Go

// Copyright 2021 DocDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package integration
import (
"math"
"testing"
"go.mongodb.org/mongo-driver/bson"
)
func TestQueryElementCompatExist(t *testing.T) {
t.Parallel()
testCases := map[string]queryCompatTestCase{
"IDExistsTrue": {
filter: bson.D{{"_id", bson.D{{"$exists", true}}}},
},
"IDExistsFalse": {
filter: bson.D{{"_id", bson.D{{"$exists", false}}}},
resultType: EmptyResult,
},
"ExistsSecondField": {
filter: bson.D{{"v", bson.D{{"$exists", true}}}},
},
"NonExistentField": {
filter: bson.D{{"non-existent", bson.D{{"$exists", true}}}},
resultType: EmptyResult,
},
"ExistsFalse": {
filter: bson.D{{"field", bson.D{{"$exists", false}}}},
},
"NonBool": {
filter: bson.D{{"_id", bson.D{{"$exists", -123}}}},
},
}
testQueryCompat(t, testCases)
}
func TestQueryElementCompatElementType(t *testing.T) {
t.Parallel()
testCases := map[string]queryCompatTestCase{
"Document": {
filter: bson.D{{"v", bson.D{{"$type", "object"}}}},
},
"Array": {
filter: bson.D{{"v", bson.D{{"$type", "array"}}}},
},
"Double": {
filter: bson.D{{"v", bson.D{{"$type", "double"}}}},
},
"String": {
filter: bson.D{{"v", bson.D{{"$type", "string"}}}},
},
"Binary": {
filter: bson.D{{"v", bson.D{{"$type", "binData"}}}},
},
"ObjectID": {
filter: bson.D{{"v", bson.D{{"$type", "objectId"}}}},
},
"Bool": {
filter: bson.D{{"v", bson.D{{"$type", "bool"}}}},
},
"Datetime": {
filter: bson.D{{"v", bson.D{{"$type", "date"}}}},
},
"Null": {
filter: bson.D{{"v", bson.D{{"$type", "null"}}}},
},
"Regex": {
filter: bson.D{{"v", bson.D{{"$type", "regex"}}}},
},
"Integer": {
filter: bson.D{{"v", bson.D{{"$type", "int"}}}},
},
"Timestamp": {
filter: bson.D{{"v", bson.D{{"$type", "timestamp"}}}},
},
"Long": {
filter: bson.D{{"v", bson.D{{"$type", "long"}}}},
},
"Number": {
filter: bson.D{{"v", bson.D{{"$type", "number"}}}},
},
"BadTypeCode": {
filter: bson.D{{"v", bson.D{{"$type", 42}}}},
resultType: EmptyResult,
},
"BadTypeName": {
filter: bson.D{{"v", bson.D{{"$type", "float"}}}},
resultType: EmptyResult,
},
"IntegerNumericalInput": {
filter: bson.D{{"v", bson.D{{"$type", 16}}}},
},
"FloatTypeCode": {
filter: bson.D{{"v", bson.D{{"$type", 16.0}}}},
},
"TypeArrayAliases": {
filter: bson.D{{"v", bson.D{{"$type", []any{"bool", "binData"}}}}},
},
"TypeArrayCodes": {
filter: bson.D{{"v", bson.D{{"$type", []any{5, 8}}}}},
},
"TypeArrayAliasAndCodeMixed": {
filter: bson.D{{"v", bson.D{{"$type", []any{5, "binData"}}}}},
},
"TypeArrayBadValue": {
filter: bson.D{{"v", bson.D{{"$type", []any{"binData", -123}}}}},
resultType: EmptyResult,
},
"TypeArrayBadValuePlusInf": {
filter: bson.D{{"v", bson.D{{"$type", []any{"binData", math.Inf(+1)}}}}},
resultType: EmptyResult,
failsForDocDB: "https://github.com/hanzoai/docdb-DocumentDB/issues/245",
},
"TypeArrayBadValueMinusInf": {
filter: bson.D{{"v", bson.D{{"$type", []any{"binData", math.Inf(-1)}}}}},
resultType: EmptyResult,
failsForDocDB: "https://github.com/hanzoai/docdb-DocumentDB/issues/245",
},
"TypeArrayBadValueNegativeFloat": {
filter: bson.D{{"v", bson.D{{"$type", []any{"binData", -1.123}}}}},
resultType: EmptyResult,
},
"TypeArrayFloat": {
filter: bson.D{{"v", bson.D{{"$type", []any{5, 8.0}}}}},
},
}
testQueryCompat(t, testCases)
}