| 1 | // Copyright (C) MongoDB, Inc. 2023-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 readconcern_testscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern_test`/ |
| 8 | |
| 9 | import ( |
| 10 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 11 | |
| 12 | "go.mongodb.org/mongo-driver/internal/assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/" |
| 13 | "go.mongodb.org/mongo-driver/mongo/readconcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/" |
| 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 TestReadConcern_MarshalBSONValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern_test`/TestReadConcern_MarshalBSONValue().(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 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 19 | |
| 20 | testCases := []struct { |
| 21 | name string |
| 22 | rc *readconcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/.ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# |
| 23 | bytes []byte |
| 24 | wantErrorMsg *string |
| 25 | }{ |
| 26 | { |
| 27 | name: "local", |
| 28 | rc: readconcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/.Localscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Local().(), |
| 29 | bytes: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.BuildDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocument().(nil, bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendStringElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendStringElement().(nil, "level", "local")), |
| 30 | wantErrorMsg: nil, |
| 31 | }, |
| 32 | { |
| 33 | name: "empty", |
| 34 | rc: readconcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/.Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(), |
| 35 | bytes: bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.BuildDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocument().(nil, nil), |
| 36 | wantErrorMsg: nil, |
| 37 | }, |
| 38 | { |
| 39 | name: "nil", |
| 40 | rc: nil, |
| 41 | bytes: nil, |
| 42 | wantErrorMsg: func() *string { |
| 43 | msg := "cannot marshal nil ReadConcern" |
| 44 | return &msg |
| 45 | }(), |
| 46 | }, |
| 47 | } |
| 48 | |
| 49 | for _, tc := range testCases { |
| 50 | tc := tc // Capture range variable. |
| 51 | |
| 52 | 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#) { |
| 53 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 54 | |
| 55 | _, b, err := tc.rc.MarshalBSONValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#MarshalBSONValue().() |
| 56 | 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.bytes, b, "expected and actual outputs do not match") |
| 57 | if tc.wantErrorMsg == nil { |
| 58 | 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, "an unexpected error is returned") |
| 59 | } else { |
| 60 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.ErrorContainsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/ErrorContains().(t, err, *tc.wantErrorMsg, "expected and actual errors do not match") |
| 61 | } |
| 62 | }) |
| 63 | } |
| 64 | } |