| 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package mongoscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/ |
| 8 | |
| 9 | import ( |
| 10 | "errorsscip-go gomod github.com/golang/go/src go1.18 errors/" |
| 11 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 13 | |
| 14 | "go.mongodb.org/mongo-driver/bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/" |
| 15 | "go.mongodb.org/mongo-driver/bson/bsoncodecscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsoncodec`/" |
| 16 | "go.mongodb.org/mongo-driver/bson/bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/" |
| 17 | "go.mongodb.org/mongo-driver/bson/primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/" |
| 18 | "go.mongodb.org/mongo-driver/internal/assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/" |
| 19 | "go.mongodb.org/mongo-driver/internal/codecutilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/codecutil`/" |
| 20 | "go.mongodb.org/mongo-driver/internal/requirescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/require`/" |
| 21 | "go.mongodb.org/mongo-driver/mongo/optionsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/" |
| 22 | "go.mongodb.org/mongo-driver/x/bsonx/bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/" |
| 23 | ) |
| 24 | |
| 25 | func TestEnsureIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/TestEnsureID().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 26 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 27 | |
| 28 | oid := primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.NewObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/NewObjectID().() |
| 29 | |
| 30 | testCases := []struct { |
| 31 | description string |
| 32 | // TODO: Registry? DecodeOptions? |
| 33 | doc bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document# |
| 34 | oid primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID# |
| 35 | want bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document# |
| 36 | wantID interface{} |
| 37 | }{ |
| 38 | { |
| 39 | description: "missing _id should be first element", |
| 40 | doc: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 41 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 42 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 43 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 44 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 45 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 46 | AppendObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendObjectID().("_id", oid). |
| 47 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 48 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 49 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 50 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 51 | wantID: oid, |
| 52 | }, |
| 53 | { |
| 54 | description: "existing ObjectID _id as should remain in place", |
| 55 | doc: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 56 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 57 | AppendObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendObjectID().("_id", oid). |
| 58 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 59 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 60 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 61 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 62 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 63 | AppendObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendObjectID().("_id", oid). |
| 64 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 65 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 66 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 67 | wantID: oid, |
| 68 | }, |
| 69 | { |
| 70 | description: "existing float _id as should remain in place", |
| 71 | doc: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 72 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 73 | AppendDoublescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendDouble().("_id", 3.14159). |
| 74 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 75 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 76 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 77 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 78 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 79 | AppendDoublescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendDouble().("_id", 3.14159). |
| 80 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 81 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 82 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 83 | wantID: 3.14159, |
| 84 | }, |
| 85 | { |
| 86 | description: "existing float _id as first element should remain first element", |
| 87 | doc: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 88 | AppendDoublescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendDouble().("_id", 3.14159). |
| 89 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 90 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 91 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 92 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 93 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 94 | AppendDoublescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendDouble().("_id", 3.14159). |
| 95 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 96 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "quix"). |
| 97 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("hello", "world"). |
| 98 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 99 | wantID: 3.14159, |
| 100 | }, |
| 101 | { |
| 102 | description: "existing binary _id as first field should not be overwritten", |
| 103 | doc: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 104 | AppendBinaryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendBinary().("bin", 0, []byte{0, 0, 0}). |
| 105 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("_id", "LongEnoughIdentifier"). |
| 106 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 107 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 108 | AppendBinaryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendBinary().("bin", 0, []byte{0, 0, 0}). |
| 109 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("_id", "LongEnoughIdentifier"). |
| 110 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 111 | wantID: "LongEnoughIdentifier", |
| 112 | }, |
| 113 | } |
| 114 | |
| 115 | for _, tc := range testCases { |
| 116 | tc := tc // Capture range variable. |
| 117 | |
| 118 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.description, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 119 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 120 | |
| 121 | got, gotID, err := ensureIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/ensureID().(tc.doc, oid, nil, nil) |
| 122 | requirescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/require`/.NoErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/require`/NoError().(t, err, "ensureID error") |
| 123 | |
| 124 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tc.want, got, "expected and actual documents are different") |
| 125 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tc.wantID, gotID, "expected and actual IDs are different") |
| 126 | |
| 127 | // Ensure that if the unmarshaled "_id" value is a |
| 128 | // primitive.ObjectID that it is a deep copy and does not share any |
| 129 | // memory with the document byte slice. |
| 130 | if oid, ok := gotID.(primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID#); ok { |
| 131 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.DifferentAddressRangesscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/DifferentAddressRanges().(t, tc.doc, oid[:]) |
| 132 | } |
| 133 | }) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func TestEnsureID_NilObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/TestEnsureID_NilObjectID().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 138 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 139 | |
| 140 | doc := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 141 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 142 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().() |
| 143 | |
| 144 | got, gotIDI, err := ensureIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/ensureID().(doc, primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.NilObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/NilObjectID., nil, nil) |
| 145 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.NoErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/NoError().(t, err) |
| 146 | |
| 147 | gotID, ok := gotIDI.(primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID#) |
| 148 | |
| 149 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Truescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/True().(t, ok) |
| 150 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.NotEqualscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/NotEqual().(t, primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.NilObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/NilObjectID., gotID) |
| 151 | |
| 152 | want := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 153 | AppendObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendObjectID().("_id", gotID). |
| 154 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar"). |
| 155 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().() |
| 156 | |
| 157 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, want, got) |
| 158 | } |
| 159 | |
| 160 | func TestMarshalAggregatePipelinescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/TestMarshalAggregatePipeline().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 161 | // []byte of [{{"$limit", 12345}}] |
| 162 | index, arr := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendArrayStartscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayStart().(nil) |
| 163 | dindex, arr := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendDocumentElementStartscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDocumentElementStart().(arr, "0") |
| 164 | arr = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendInt32Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt32Element().(arr, "$limit", 12345) |
| 165 | arr, _ = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendDocumentEndscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDocumentEnd().(arr, dindex) |
| 166 | arr, _ = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendArrayEndscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayEnd().(arr, index) |
| 167 | |
| 168 | // []byte of {{"x", 1}} |
| 169 | index, doc := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendDocumentStartscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDocumentStart().(nil) |
| 170 | doc = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendInt32Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt32Element().(doc, "x", 1) |
| 171 | doc, _ = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendDocumentEndscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDocumentEnd().(doc, index) |
| 172 | |
| 173 | // bsoncore.Array of [{{"$merge", {}}}] |
| 174 | mergeStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 175 | StartDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#StartDocument().("$merge"). |
| 176 | FinishDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#FinishDocument().(). |
| 177 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().() |
| 178 | arrMergeStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(mergeStage).Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 179 | |
| 180 | fooStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().().AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("foo", "bar").Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().() |
| 181 | bazStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().().AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("baz", "qux").Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().() |
| 182 | outStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().().AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("$out", "myColl").Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().() |
| 183 | |
| 184 | // bsoncore.Array of [{{"foo", "bar"}}, {{"baz", "qux"}}, {{"$out", "myColl"}}] |
| 185 | arrOutStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().(). |
| 186 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(fooStage). |
| 187 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(bazStage). |
| 188 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(outStage). |
| 189 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 190 | |
| 191 | // bsoncore.Array of [{{"foo", "bar"}}, {{"$out", "myColl"}}, {{"baz", "qux"}}] |
| 192 | arrMiddleOutStage := bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().(). |
| 193 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(fooStage). |
| 194 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(outStage). |
| 195 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument().(bazStage). |
| 196 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 197 | |
| 198 | testCases := []struct { |
| 199 | name string |
| 200 | pipeline interface{} |
| 201 | arr bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A# |
| 202 | hasOutputStage bool |
| 203 | err error |
| 204 | }{ |
| 205 | { |
| 206 | "Pipeline/error", |
| 207 | Pipelinescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/Pipeline#{{{"hello", func() {}}}}, |
| 208 | nil, |
| 209 | false, |
| 210 | MarshalErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#{Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Value.: primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/D#{}, Errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("no encoder found for func()")}, |
| 211 | }, |
| 212 | { |
| 213 | "Pipeline/success", |
| 214 | Pipelinescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/Pipeline#{{{"hello", "world"}}, {{"pi", 3.14159}}}, |
| 215 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 216 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"hello", "world"}}, |
| 217 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"pi", 3.14159}}, |
| 218 | }, |
| 219 | false, |
| 220 | nil, |
| 221 | }, |
| 222 | { |
| 223 | "bson.A", |
| 224 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 225 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", 12345}}, |
| 226 | }, |
| 227 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 228 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", 12345}}, |
| 229 | }, |
| 230 | false, |
| 231 | nil, |
| 232 | }, |
| 233 | { |
| 234 | "[]bson.D", |
| 235 | []bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{{"$limit", 12345}}}, |
| 236 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 237 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", 12345}}, |
| 238 | }, |
| 239 | false, |
| 240 | nil, |
| 241 | }, |
| 242 | { |
| 243 | "primitive.A/error", |
| 244 | primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/A#{"5"}, |
| 245 | nil, |
| 246 | false, |
| 247 | MarshalErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#{Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Value.: "", Errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("WriteString can only write while positioned on a Element or Value but is positioned on a TopLevel")}, |
| 248 | }, |
| 249 | { |
| 250 | "primitive.A/success", |
| 251 | primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/A#{bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, map[string]interface{}{"$count": "foobar"}}, |
| 252 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 253 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int(12345)}}, |
| 254 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$count", "foobar"}}, |
| 255 | }, |
| 256 | false, |
| 257 | nil, |
| 258 | }, |
| 259 | { |
| 260 | "bson.A/error", |
| 261 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{"5"}, |
| 262 | nil, |
| 263 | false, |
| 264 | MarshalErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#{Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Value.: "", Errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("WriteString can only write while positioned on a Element or Value but is positioned on a TopLevel")}, |
| 265 | }, |
| 266 | { |
| 267 | "bson.A/success", |
| 268 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, map[string]interface{}{"$count": "foobar"}}, |
| 269 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 270 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, |
| 271 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$count", "foobar"}}, |
| 272 | }, |
| 273 | false, |
| 274 | nil, |
| 275 | }, |
| 276 | { |
| 277 | "[]interface{}/error", |
| 278 | []interface{}{"5"}, |
| 279 | nil, |
| 280 | false, |
| 281 | MarshalErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#{Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Value.: "", Errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("WriteString can only write while positioned on a Element or Value but is positioned on a TopLevel")}, |
| 282 | }, |
| 283 | { |
| 284 | "[]interface{}/success", |
| 285 | []interface{}{bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, map[string]interface{}{"$count": "foobar"}}, |
| 286 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 287 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, |
| 288 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$count", "foobar"}}, |
| 289 | }, |
| 290 | false, |
| 291 | nil, |
| 292 | }, |
| 293 | { |
| 294 | "bsoncodec.ValueMarshaler/MarshalBSONValue error", |
| 295 | bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("MarshalBSONValue error")}, |
| 296 | nil, |
| 297 | false, |
| 298 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("MarshalBSONValue error"), |
| 299 | }, |
| 300 | { |
| 301 | "bsoncodec.ValueMarshaler/not array", |
| 302 | bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t.: bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Stringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/String.}, |
| 303 | nil, |
| 304 | false, |
| 305 | fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("ValueMarshaler returned a %v, but was expecting %v", bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Stringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/String., bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Arrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/Array.), |
| 306 | }, |
| 307 | { |
| 308 | "bsoncodec.ValueMarshaler/UnmarshalBSONValue error", |
| 309 | bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("UnmarshalBSONValue error")}, |
| 310 | nil, |
| 311 | false, |
| 312 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("UnmarshalBSONValue error"), |
| 313 | }, |
| 314 | { |
| 315 | "bsoncodec.ValueMarshaler/success", |
| 316 | bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t.: bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Arrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/Array., datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#data.: arr}, |
| 317 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 318 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, |
| 319 | }, |
| 320 | false, |
| 321 | nil, |
| 322 | }, |
| 323 | { |
| 324 | "bsoncodec.ValueMarshaler/success nil", |
| 325 | bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t.: bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Arrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/Array.}, |
| 326 | nil, |
| 327 | false, |
| 328 | nil, |
| 329 | }, |
| 330 | { |
| 331 | "nil", |
| 332 | nil, |
| 333 | nil, |
| 334 | false, |
| 335 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("can only marshal slices and arrays into aggregation pipelines, but got invalid"), |
| 336 | }, |
| 337 | { |
| 338 | "not array or slice", |
| 339 | int64(42), |
| 340 | nil, |
| 341 | false, |
| 342 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("can only marshal slices and arrays into aggregation pipelines, but got int64"), |
| 343 | }, |
| 344 | { |
| 345 | "array/error", |
| 346 | [1]interface{}{int64(42)}, |
| 347 | nil, |
| 348 | false, |
| 349 | MarshalErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#{Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Value.: int64(0), Errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("WriteInt64 can only write while positioned on a Element or Value but is positioned on a TopLevel")}, |
| 350 | }, |
| 351 | { |
| 352 | "array/success", |
| 353 | [1]interface{}{primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/D#{{"$limit", int64(12345)}}}, |
| 354 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 355 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int64(12345)}}, |
| 356 | }, |
| 357 | false, |
| 358 | nil, |
| 359 | }, |
| 360 | { |
| 361 | "slice/error", |
| 362 | []interface{}{int64(42)}, |
| 363 | nil, |
| 364 | false, |
| 365 | MarshalErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#{Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Value.: int64(0), Errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/MarshalError#Err.: errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("WriteInt64 can only write while positioned on a Element or Value but is positioned on a TopLevel")}, |
| 366 | }, |
| 367 | { |
| 368 | "slice/success", |
| 369 | []interface{}{primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/D#{{"$limit", int64(12345)}}}, |
| 370 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 371 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int64(12345)}}, |
| 372 | }, |
| 373 | false, |
| 374 | nil, |
| 375 | }, |
| 376 | { |
| 377 | "hasOutputStage/out", |
| 378 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 379 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$out", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{ |
| 380 | {"db", "output-db"}, |
| 381 | {"coll", "output-collection"}, |
| 382 | }}}, |
| 383 | }, |
| 384 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 385 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$out", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{ |
| 386 | {"db", "output-db"}, |
| 387 | {"coll", "output-collection"}, |
| 388 | }}}, |
| 389 | }, |
| 390 | true, |
| 391 | nil, |
| 392 | }, |
| 393 | { |
| 394 | "hasOutputStage/merge", |
| 395 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 396 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$merge", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{ |
| 397 | {"into", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{ |
| 398 | {"db", "output-db"}, |
| 399 | {"coll", "output-collection"}, |
| 400 | }}, |
| 401 | }}}, |
| 402 | }, |
| 403 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 404 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$merge", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{ |
| 405 | {"into", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{ |
| 406 | {"db", "output-db"}, |
| 407 | {"coll", "output-collection"}, |
| 408 | }}, |
| 409 | }}}, |
| 410 | }, |
| 411 | true, |
| 412 | nil, |
| 413 | }, |
| 414 | { |
| 415 | "semantic single document/bson.D", |
| 416 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"x", 1}}, |
| 417 | nil, |
| 418 | false, |
| 419 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("primitive.D is not an allowed pipeline type as it represents a single document. Use bson.A or mongo.Pipeline instead"), |
| 420 | }, |
| 421 | { |
| 422 | "semantic single document/bson.Raw", |
| 423 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Rawscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/Raw#(doc), |
| 424 | nil, |
| 425 | false, |
| 426 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("bson.Raw is not an allowed pipeline type as it represents a single document. Use bson.A or mongo.Pipeline instead"), |
| 427 | }, |
| 428 | { |
| 429 | "semantic single document/bsoncore.Document", |
| 430 | bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#(doc), |
| 431 | nil, |
| 432 | false, |
| 433 | errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("bsoncore.Document is not an allowed pipeline type as it represents a single document. Use bson.A or mongo.Pipeline instead"), |
| 434 | }, |
| 435 | { |
| 436 | "semantic single document/empty bson.D", |
| 437 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{}, |
| 438 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{}, |
| 439 | false, |
| 440 | nil, |
| 441 | }, |
| 442 | { |
| 443 | "semantic single document/empty bson.Raw", |
| 444 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Rawscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/Raw#{}, |
| 445 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{}, |
| 446 | false, |
| 447 | nil, |
| 448 | }, |
| 449 | { |
| 450 | "semantic single document/empty bsoncore.Document", |
| 451 | bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#{}, |
| 452 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{}, |
| 453 | false, |
| 454 | nil, |
| 455 | }, |
| 456 | { |
| 457 | "bsoncore.Array/success", |
| 458 | bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Arrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Array#(arr), |
| 459 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 460 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$limit", int32(12345)}}, |
| 461 | }, |
| 462 | false, |
| 463 | nil, |
| 464 | }, |
| 465 | { |
| 466 | "bsoncore.Array/mergeStage", |
| 467 | arrMergeStage, |
| 468 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 469 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$merge", bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{}}}, |
| 470 | }, |
| 471 | true, |
| 472 | nil, |
| 473 | }, |
| 474 | { |
| 475 | "bsoncore.Array/outStage", |
| 476 | arrOutStage, |
| 477 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 478 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"foo", "bar"}}, |
| 479 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"baz", "qux"}}, |
| 480 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$out", "myColl"}}, |
| 481 | }, |
| 482 | true, |
| 483 | nil, |
| 484 | }, |
| 485 | { |
| 486 | "bsoncore.Array/middleOutStage", |
| 487 | arrMiddleOutStage, |
| 488 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Ascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/A#{ |
| 489 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"foo", "bar"}}, |
| 490 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"$out", "myColl"}}, |
| 491 | bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{"baz", "qux"}}, |
| 492 | }, |
| 493 | false, |
| 494 | nil, |
| 495 | }, |
| 496 | } |
| 497 | |
| 498 | for _, tc := range testCases { |
| 499 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 500 | arr, hasOutputStage, err := marshalAggregatePipelinescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/marshalAggregatePipeline().(tc.pipeline, nil, nil) |
| 501 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tc.hasOutputStage, hasOutputStage, "expected hasOutputStage %v, got %v", |
| 502 | tc.hasOutputStage, hasOutputStage) |
| 503 | if tc.err != nil { |
| 504 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.NotNilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/NotNil().(t, err) |
| 505 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.EqualErrorscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/EqualError().(t, err, tc.err.Error()) |
| 506 | } else { |
| 507 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Nilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Nil().(t, err) |
| 508 | } |
| 509 | |
| 510 | var expected bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document# |
| 511 | if tc.arr != nil { |
| 512 | _, expectedBSON, err := bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.MarshalValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/MarshalValue().(tc.arr) |
| 513 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Nilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Nil().(t, err, "MarshalValue error: %v", err) |
| 514 | expected = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#(expectedBSON) |
| 515 | } |
| 516 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, expected, arr, "expected array %v, got %v", expected, arr) |
| 517 | }) |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | func TestMarshalValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/TestMarshalValue().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 522 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 523 | |
| 524 | valueMarshaler := bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{ |
| 525 | tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t.: bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.TypeStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/TypeString., |
| 526 | datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#data.: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendString().(nil, "foo"), |
| 527 | } |
| 528 | |
| 529 | testCases := []struct { |
| 530 | name string |
| 531 | value interface{} |
| 532 | bsonOpts *optionsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/.BSONOptionsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions# |
| 533 | registry *bsoncodecscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsoncodec`/.Registryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsoncodec`/Registry# |
| 534 | want bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value# |
| 535 | wantErr error |
| 536 | }{ |
| 537 | { |
| 538 | name: "nil document", |
| 539 | value: nil, |
| 540 | wantErr: codecutilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/codecutil`/.ErrNilValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/codecutil`/ErrNilValue., |
| 541 | }, |
| 542 | { |
| 543 | name: "value marshaler", |
| 544 | value: valueMarshaler, |
| 545 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#{ |
| 546 | Typescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#Type.: valueMarshaler.tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t., |
| 547 | Datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#Data.: valueMarshaler.datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#data., |
| 548 | }, |
| 549 | }, |
| 550 | { |
| 551 | name: "document", |
| 552 | value: bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.Dscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/D#{{Keyscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/E#Key.: "x", Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/E#Value.: int64(1)}}, |
| 553 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#{ |
| 554 | Typescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#Type.: bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.TypeEmbeddedDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/TypeEmbeddedDocument., |
| 555 | Datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#Data.: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 556 | AppendInt64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendInt64().("x", 1). |
| 557 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 558 | }, |
| 559 | }, |
| 560 | { |
| 561 | name: "custom encode options", |
| 562 | value: struct { |
| 563 | Int int64 |
| 564 | NilBytes []byte |
| 565 | NilMap map[string]interface{} |
| 566 | NilStrings []string |
| 567 | ZeroStruct struct{ X int } `bson:"_,omitempty"` |
| 568 | StringerMap map[*bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.RawValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/RawValue#]bool |
| 569 | BSONField string `json:"jsonField"` |
| 570 | }{ |
| 571 | Int: 1, |
| 572 | NilBytes: nil, |
| 573 | NilMap: nil, |
| 574 | NilStrings: nil, |
| 575 | StringerMap: map[*bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.RawValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/RawValue#]bool{{}: true}, |
| 576 | }, |
| 577 | bsonOpts: &optionsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/.BSONOptionsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#{ |
| 578 | IntMinSizescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#IntMinSize.: true, |
| 579 | NilByteSliceAsEmptyscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#NilByteSliceAsEmpty.: true, |
| 580 | NilMapAsEmptyscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#NilMapAsEmpty.: true, |
| 581 | NilSliceAsEmptyscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#NilSliceAsEmpty.: true, |
| 582 | OmitZeroStructscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#OmitZeroStruct.: true, |
| 583 | StringifyMapKeysWithFmtscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#StringifyMapKeysWithFmt.: true, |
| 584 | UseJSONStructTagsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/options`/BSONOptions#UseJSONStructTags.: true, |
| 585 | }, |
| 586 | want: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.Valuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#{ |
| 587 | Typescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#Type.: bsonscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/.TypeEmbeddedDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson`/TypeEmbeddedDocument., |
| 588 | Datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Value#Data.: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 589 | AppendInt32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendInt32().("int", 1). |
| 590 | AppendBinaryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendBinary().("nilbytes", 0, []byte{}). |
| 591 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendDocument().("nilmap", bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().().Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().()). |
| 592 | AppendArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendArray().("nilstrings", bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().()). |
| 593 | AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendDocument().("stringermap", bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.NewDocumentBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewDocumentBuilder().(). |
| 594 | AppendBooleanscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendBoolean().("", true). |
| 595 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().()). |
| 596 | AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#AppendString().("jsonField", ""). |
| 597 | Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/DocumentBuilder#Build().(), |
| 598 | }, |
| 599 | }, |
| 600 | } |
| 601 | for _, tc := range testCases { |
| 602 | tc := tc // Capture range variable. |
| 603 | |
| 604 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 605 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 606 | |
| 607 | got, err := marshalValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/marshalValue().(tc.value, tc.bsonOpts, tc.registry) |
| 608 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.EqualBSONscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/EqualBSON().(t, tc.want, got) |
| 609 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tc.wantErr, err, "expected and actual error do not match") |
| 610 | }) |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | var _ bsoncodecscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsoncodec`/.ValueMarshalerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsoncodec`/ValueMarshaler# = bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#{} |
| 615 | |
| 616 | type bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh# struct { |
| 617 | tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t. bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Typescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/Type# |
| 618 | datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#data. []byte |
| 619 | errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#err. error |
| 620 | } |
| 621 | |
| 622 | func (b bvMarshscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#) MarshalBSONValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#MarshalBSONValue().() (bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Typescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/Type#, []byte, error) { |
| 623 | return b.tscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#t., b.datascip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#data., b.errscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo`/bvMarsh#err. |
| 624 | } |