| 1 | // Copyright (C) MongoDB, Inc. 2024-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 wiremessagescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/ |
| 8 | |
| 9 | import ( |
| 10 | "mathscip-go gomod github.com/golang/go/src go1.18 math/" |
| 11 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 12 | |
| 13 | "go.mongodb.org/mongo-driver/internal/assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/" |
| 14 | "go.mongodb.org/mongo-driver/x/bsonx/bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/" |
| 15 | ) |
| 16 | |
| 17 | func TestAppendHeaderStartscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestAppendHeaderStart().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 18 | testCases := []struct { |
| 19 | desc string |
| 20 | dst []byte |
| 21 | reqid int32 |
| 22 | respto int32 |
| 23 | opcode OpCodescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpCode# |
| 24 | wantIdx int32 |
| 25 | wantBytes []byte |
| 26 | }{ |
| 27 | { |
| 28 | desc: "OP_MSG", |
| 29 | reqid: 2, |
| 30 | respto: 1, |
| 31 | opcode: OpMsgscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpMsg., |
| 32 | wantIdx: 0, |
| 33 | wantBytes: []byte{0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 221, 7, 0, 0}, |
| 34 | }, |
| 35 | { |
| 36 | desc: "OP_QUERY", |
| 37 | reqid: 2, |
| 38 | respto: 1, |
| 39 | opcode: OpQueryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpQuery., |
| 40 | wantIdx: 0, |
| 41 | wantBytes: []byte{0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 212, 7, 0, 0}, |
| 42 | }, |
| 43 | { |
| 44 | desc: "non-empty buffer", |
| 45 | dst: []byte{0, 99}, |
| 46 | reqid: 2, |
| 47 | respto: 1, |
| 48 | opcode: OpMsgscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpMsg., |
| 49 | wantIdx: 2, |
| 50 | wantBytes: []byte{0, 99, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 221, 7, 0, 0}, |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | for _, tc := range testCases { |
| 55 | tc := tc // Capture range variable. |
| 56 | |
| 57 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 58 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 59 | |
| 60 | idx, b := AppendHeaderStartscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/AppendHeaderStart().(tc.dst, tc.reqid, tc.respto, tc.opcode) |
| 61 | 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.wantIdx, idx, "appended slice index does not match") |
| 62 | 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.wantBytes, b, "appended bytes do not match") |
| 63 | }) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func TestReadHeaderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestReadHeader().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 68 | testCases := []struct { |
| 69 | desc string |
| 70 | src []byte |
| 71 | wantLength int32 |
| 72 | wantRequestID int32 |
| 73 | wantResponseTo int32 |
| 74 | wantOpcode OpCodescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpCode# |
| 75 | wantRem []byte |
| 76 | wantOK bool |
| 77 | }{ |
| 78 | { |
| 79 | desc: "OP_MSG", |
| 80 | src: []byte{0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 221, 7, 0, 0}, |
| 81 | wantLength: 0, |
| 82 | wantRequestID: 2, |
| 83 | wantResponseTo: 1, |
| 84 | wantOpcode: OpMsgscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpMsg., |
| 85 | wantRem: []byte{}, |
| 86 | wantOK: true, |
| 87 | }, |
| 88 | { |
| 89 | desc: "OP_QUERY", |
| 90 | src: []byte{0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 212, 7, 0, 0}, |
| 91 | wantLength: 0, |
| 92 | wantRequestID: 2, |
| 93 | wantResponseTo: 1, |
| 94 | wantOpcode: OpQueryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/OpQuery., |
| 95 | wantRem: []byte{}, |
| 96 | wantOK: true, |
| 97 | }, |
| 98 | { |
| 99 | desc: "not enough bytes", |
| 100 | src: []byte{0, 99}, |
| 101 | wantLength: 0, |
| 102 | wantRequestID: 0, |
| 103 | wantResponseTo: 0, |
| 104 | wantOpcode: 0, |
| 105 | wantRem: []byte{0, 99}, |
| 106 | wantOK: false, |
| 107 | }, |
| 108 | { |
| 109 | desc: "nil", |
| 110 | src: nil, |
| 111 | wantLength: 0, |
| 112 | wantRequestID: 0, |
| 113 | wantResponseTo: 0, |
| 114 | wantOpcode: 0, |
| 115 | wantRem: nil, |
| 116 | wantOK: false, |
| 117 | }, |
| 118 | } |
| 119 | |
| 120 | for _, tc := range testCases { |
| 121 | tc := tc // Capture range variable. |
| 122 | |
| 123 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 124 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 125 | |
| 126 | length, requestID, responseTo, opcode, rem, ok := ReadHeaderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/ReadHeader().(tc.src) |
| 127 | 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.wantLength, length, "length does not match") |
| 128 | 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.wantRequestID, requestID, "requestID does not match") |
| 129 | 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.wantResponseTo, responseTo, "responseTo does not match") |
| 130 | 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.wantOpcode, opcode, "OpCode does not match") |
| 131 | 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.wantRem, rem, "remaining bytes do not match") |
| 132 | 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.wantOK, ok, "OK does not match") |
| 133 | }) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func TestReadMsgSectionDocumentSequencescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestReadMsgSectionDocumentSequence().(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 | testCases := []struct { |
| 139 | desc string |
| 140 | src []byte |
| 141 | wantIdentifier string |
| 142 | wantDocs []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# |
| 143 | wantRem []byte |
| 144 | wantOK bool |
| 145 | }{ |
| 146 | { |
| 147 | desc: "valid document sequence", |
| 148 | // Data: | len=17 | "id" | empty doc | empty doc | |
| 149 | src: []byte{17, 0, 0, 0, 105, 100, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0}, |
| 150 | wantIdentifier: "id", |
| 151 | wantDocs: []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#{ |
| 152 | {0x5, 0x0, 0x0, 0x0, 0x0}, |
| 153 | {0x5, 0x0, 0x0, 0x0, 0x0}, |
| 154 | }, |
| 155 | wantRem: []byte{}, |
| 156 | wantOK: true, |
| 157 | }, |
| 158 | { |
| 159 | desc: "valid document sequence with remaining bytes", |
| 160 | // Data: | len=17 | "id" | empty doc | empty doc | rem | |
| 161 | src: []byte{17, 0, 0, 0, 105, 100, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 99, 99}, |
| 162 | wantIdentifier: "id", |
| 163 | wantDocs: []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#{ |
| 164 | {0x5, 0x0, 0x0, 0x0, 0x0}, |
| 165 | {0x5, 0x0, 0x0, 0x0, 0x0}, |
| 166 | }, |
| 167 | wantRem: []byte{99, 99}, |
| 168 | wantOK: true, |
| 169 | }, |
| 170 | { |
| 171 | desc: "not enough bytes", |
| 172 | src: []byte{0, 1}, |
| 173 | wantIdentifier: "", |
| 174 | wantDocs: nil, |
| 175 | wantRem: []byte{0, 1}, |
| 176 | wantOK: false, |
| 177 | }, |
| 178 | { |
| 179 | desc: "incorrect size", |
| 180 | src: []byte{3, 0, 0}, |
| 181 | wantIdentifier: "", |
| 182 | wantDocs: nil, |
| 183 | wantRem: []byte{3, 0, 0}, |
| 184 | wantOK: false, |
| 185 | }, |
| 186 | { |
| 187 | desc: "insufficient size", |
| 188 | src: []byte{4, 0, 0}, |
| 189 | wantIdentifier: "", |
| 190 | wantDocs: nil, |
| 191 | wantRem: []byte{4, 0, 0}, |
| 192 | wantOK: false, |
| 193 | }, |
| 194 | { |
| 195 | desc: "nil", |
| 196 | src: nil, |
| 197 | wantIdentifier: "", |
| 198 | wantDocs: nil, |
| 199 | wantRem: nil, |
| 200 | wantOK: false, |
| 201 | }, |
| 202 | } |
| 203 | |
| 204 | for _, tc := range testCases { |
| 205 | tc := tc // Capture range variable. |
| 206 | |
| 207 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 208 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 209 | |
| 210 | identifier, docs, rem, ok := ReadMsgSectionDocumentSequencescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/ReadMsgSectionDocumentSequence().(tc.src) |
| 211 | 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.wantIdentifier, identifier, "identifier does not match") |
| 212 | 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.wantDocs, docs, "docs do not match") |
| 213 | 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.wantRem, rem, "responseTo does not match") |
| 214 | 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.wantOK, ok, "OK does not match") |
| 215 | }) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func TestAppendi32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestAppendi32().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 220 | testCases := []struct { |
| 221 | desc string |
| 222 | dst []byte |
| 223 | x int32 |
| 224 | want []byte |
| 225 | }{ |
| 226 | { |
| 227 | desc: "0", |
| 228 | x: 0, |
| 229 | want: []byte{0, 0, 0, 0}, |
| 230 | }, |
| 231 | { |
| 232 | desc: "1", |
| 233 | x: 1, |
| 234 | want: []byte{1, 0, 0, 0}, |
| 235 | }, |
| 236 | { |
| 237 | desc: "-1", |
| 238 | x: -1, |
| 239 | want: []byte{255, 255, 255, 255}, |
| 240 | }, |
| 241 | { |
| 242 | desc: "max", |
| 243 | x: mathscip-go gomod github.com/golang/go/src go1.18 math/.MaxInt32scip-go gomod github.com/golang/go/src go1.18 math/MaxInt32., |
| 244 | want: []byte{255, 255, 255, 127}, |
| 245 | }, |
| 246 | { |
| 247 | desc: "min", |
| 248 | x: mathscip-go gomod github.com/golang/go/src go1.18 math/.MinInt32scip-go gomod github.com/golang/go/src go1.18 math/MinInt32., |
| 249 | want: []byte{0, 0, 0, 128}, |
| 250 | }, |
| 251 | { |
| 252 | desc: "non-empty dst", |
| 253 | dst: []byte{0, 1, 2, 3}, |
| 254 | x: 1, |
| 255 | want: []byte{0, 1, 2, 3, 1, 0, 0, 0}, |
| 256 | }, |
| 257 | } |
| 258 | |
| 259 | for _, tc := range testCases { |
| 260 | tc := tc // Capture range variable. |
| 261 | |
| 262 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 263 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 264 | |
| 265 | b := appendi32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/appendi32().(tc.dst, tc.x) |
| 266 | 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, b, "bytes do not match") |
| 267 | }) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | func TestAppendi64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestAppendi64().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 272 | testCases := []struct { |
| 273 | desc string |
| 274 | dst []byte |
| 275 | x int64 |
| 276 | want []byte |
| 277 | }{ |
| 278 | { |
| 279 | desc: "0", |
| 280 | x: 0, |
| 281 | want: []byte{0, 0, 0, 0, 0, 0, 0, 0}, |
| 282 | }, |
| 283 | { |
| 284 | desc: "1", |
| 285 | x: 1, |
| 286 | want: []byte{1, 0, 0, 0, 0, 0, 0, 0}, |
| 287 | }, |
| 288 | { |
| 289 | desc: "-1", |
| 290 | x: -1, |
| 291 | want: []byte{255, 255, 255, 255, 255, 255, 255, 255}, |
| 292 | }, |
| 293 | { |
| 294 | desc: "max", |
| 295 | x: mathscip-go gomod github.com/golang/go/src go1.18 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.18 math/MaxInt64., |
| 296 | want: []byte{255, 255, 255, 255, 255, 255, 255, 127}, |
| 297 | }, |
| 298 | { |
| 299 | desc: "min", |
| 300 | x: mathscip-go gomod github.com/golang/go/src go1.18 math/.MinInt64scip-go gomod github.com/golang/go/src go1.18 math/MinInt64., |
| 301 | want: []byte{0, 0, 0, 0, 0, 0, 0, 128}, |
| 302 | }, |
| 303 | { |
| 304 | desc: "non-empty dst", |
| 305 | dst: []byte{0, 1, 2, 3}, |
| 306 | x: 1, |
| 307 | want: []byte{0, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0}, |
| 308 | }, |
| 309 | } |
| 310 | |
| 311 | for _, tc := range testCases { |
| 312 | tc := tc // Capture range variable. |
| 313 | |
| 314 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 315 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 316 | |
| 317 | b := appendi64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/appendi64().(tc.dst, tc.x) |
| 318 | 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, b, "bytes do not match") |
| 319 | }) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | func TestReadi32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestReadi32().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 324 | testCases := []struct { |
| 325 | desc string |
| 326 | src []byte |
| 327 | want int32 |
| 328 | wantRem []byte |
| 329 | wantOK bool |
| 330 | }{ |
| 331 | { |
| 332 | desc: "0", |
| 333 | src: []byte{0, 0, 0, 0}, |
| 334 | want: 0, |
| 335 | wantRem: []byte{}, |
| 336 | wantOK: true, |
| 337 | }, |
| 338 | { |
| 339 | desc: "1", |
| 340 | src: []byte{1, 0, 0, 0}, |
| 341 | want: 1, |
| 342 | wantRem: []byte{}, |
| 343 | wantOK: true, |
| 344 | }, |
| 345 | { |
| 346 | desc: "-1", |
| 347 | src: []byte{255, 255, 255, 255}, |
| 348 | want: -1, |
| 349 | wantRem: []byte{}, |
| 350 | wantOK: true, |
| 351 | }, |
| 352 | { |
| 353 | desc: "max", |
| 354 | src: []byte{255, 255, 255, 127}, |
| 355 | want: mathscip-go gomod github.com/golang/go/src go1.18 math/.MaxInt32scip-go gomod github.com/golang/go/src go1.18 math/MaxInt32., |
| 356 | wantRem: []byte{}, |
| 357 | wantOK: true, |
| 358 | }, |
| 359 | { |
| 360 | desc: "min", |
| 361 | src: []byte{0, 0, 0, 128}, |
| 362 | want: mathscip-go gomod github.com/golang/go/src go1.18 math/.MinInt32scip-go gomod github.com/golang/go/src go1.18 math/MinInt32., |
| 363 | wantRem: []byte{}, |
| 364 | wantOK: true, |
| 365 | }, |
| 366 | { |
| 367 | desc: "non-empty remaining", |
| 368 | src: []byte{1, 0, 0, 0, 0, 1, 2, 3}, |
| 369 | want: 1, |
| 370 | wantRem: []byte{0, 1, 2, 3}, |
| 371 | wantOK: true, |
| 372 | }, |
| 373 | { |
| 374 | desc: "not enough bytes", |
| 375 | src: []byte{0, 1, 2}, |
| 376 | want: 0, |
| 377 | wantRem: []byte{0, 1, 2}, |
| 378 | wantOK: false, |
| 379 | }, |
| 380 | { |
| 381 | desc: "nil", |
| 382 | src: nil, |
| 383 | want: 0, |
| 384 | wantRem: nil, |
| 385 | wantOK: false, |
| 386 | }, |
| 387 | } |
| 388 | |
| 389 | for _, tc := range testCases { |
| 390 | tc := tc // Capture range variable. |
| 391 | |
| 392 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 393 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 394 | |
| 395 | x, rem, ok := readi32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/readi32().(tc.src) |
| 396 | 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, x, "int32 result does not match") |
| 397 | 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.wantRem, rem, "remaining bytes do not match") |
| 398 | 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.wantOK, ok, "OK does not match") |
| 399 | }) |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | func TestReadi64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/TestReadi64().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 404 | testCases := []struct { |
| 405 | desc string |
| 406 | src []byte |
| 407 | want int64 |
| 408 | wantRem []byte |
| 409 | wantOK bool |
| 410 | }{ |
| 411 | { |
| 412 | desc: "0", |
| 413 | src: []byte{0, 0, 0, 0, 0, 0, 0, 0}, |
| 414 | want: 0, |
| 415 | wantRem: []byte{}, |
| 416 | wantOK: true, |
| 417 | }, |
| 418 | { |
| 419 | desc: "1", |
| 420 | src: []byte{1, 0, 0, 0, 0, 0, 0, 0}, |
| 421 | want: 1, |
| 422 | wantRem: []byte{}, |
| 423 | wantOK: true, |
| 424 | }, |
| 425 | { |
| 426 | desc: "-1", |
| 427 | src: []byte{255, 255, 255, 255, 255, 255, 255, 255}, |
| 428 | want: -1, |
| 429 | wantRem: []byte{}, |
| 430 | wantOK: true, |
| 431 | }, |
| 432 | { |
| 433 | desc: "max", |
| 434 | src: []byte{255, 255, 255, 255, 255, 255, 255, 127}, |
| 435 | want: mathscip-go gomod github.com/golang/go/src go1.18 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.18 math/MaxInt64., |
| 436 | wantRem: []byte{}, |
| 437 | wantOK: true, |
| 438 | }, |
| 439 | { |
| 440 | desc: "min", |
| 441 | src: []byte{0, 0, 0, 0, 0, 0, 0, 128}, |
| 442 | want: mathscip-go gomod github.com/golang/go/src go1.18 math/.MinInt64scip-go gomod github.com/golang/go/src go1.18 math/MinInt64., |
| 443 | wantRem: []byte{}, |
| 444 | wantOK: true, |
| 445 | }, |
| 446 | { |
| 447 | desc: "non-empty remaining", |
| 448 | src: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}, |
| 449 | want: 1, |
| 450 | wantRem: []byte{0, 1, 2, 3}, |
| 451 | wantOK: true, |
| 452 | }, |
| 453 | { |
| 454 | desc: "not enough bytes", |
| 455 | src: []byte{0, 1, 2, 3, 4, 5, 6}, |
| 456 | want: 0, |
| 457 | wantRem: []byte{0, 1, 2, 3, 4, 5, 6}, |
| 458 | wantOK: false, |
| 459 | }, |
| 460 | { |
| 461 | desc: "not enough bytes", |
| 462 | src: []byte{0, 1, 2, 3, 4, 5, 6}, |
| 463 | want: 0, |
| 464 | wantRem: []byte{0, 1, 2, 3, 4, 5, 6}, |
| 465 | wantOK: false, |
| 466 | }, |
| 467 | { |
| 468 | desc: "nil", |
| 469 | src: nil, |
| 470 | want: 0, |
| 471 | wantRem: nil, |
| 472 | wantOK: false, |
| 473 | }, |
| 474 | } |
| 475 | |
| 476 | for _, tc := range testCases { |
| 477 | tc := tc // Capture range variable. |
| 478 | |
| 479 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.desc, 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#) { |
| 480 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 481 | |
| 482 | x, rem, ok := readi64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage`/readi64().(tc.src) |
| 483 | 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, x, "int64 result does not match") |
| 484 | 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.wantRem, rem, "remaining bytes do not match") |
| 485 | 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.wantOK, ok, "OK does not match") |
| 486 | }) |
| 487 | } |
| 488 | } |