|
| 1 | +package command |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/mongodb/mongo-go-driver/mongo/writeconcern" |
| 7 | + "github.com/mongodb/mongo-go-driver/x/network/description" |
| 8 | +) |
| 9 | + |
| 10 | +func TestFindOneAndDelete(t *testing.T) { |
| 11 | + t.Run("Encode Write Concern for MaxWireVersion >= 4", func(t *testing.T) { |
| 12 | + desc := description.SelectedServer{ |
| 13 | + Server: description.Server{ |
| 14 | + WireVersion: &description.VersionRange{Min: 0, Max: 4}, |
| 15 | + }, |
| 16 | + } |
| 17 | + wc := writeconcern.New(writeconcern.WMajority()) |
| 18 | + cmd := FindOneAndDelete{NS: Namespace{DB: "foo", Collection: "bar"}, WriteConcern: wc} |
| 19 | + write, err := cmd.encode(desc) |
| 20 | + noerr(t, err) |
| 21 | + if write.WriteConcern != wc { |
| 22 | + t.Error("write concern should be added to write command, but is missing") |
| 23 | + } |
| 24 | + }) |
| 25 | + t.Run("Omit Write Concern for MaxWireVersion < 4", func(t *testing.T) { |
| 26 | + desc := description.SelectedServer{ |
| 27 | + Server: description.Server{ |
| 28 | + WireVersion: &description.VersionRange{Min: 0, Max: 3}, |
| 29 | + }, |
| 30 | + } |
| 31 | + wc := writeconcern.New(writeconcern.WMajority()) |
| 32 | + cmd := FindOneAndDelete{NS: Namespace{DB: "foo", Collection: "bar"}, WriteConcern: wc} |
| 33 | + write, err := cmd.encode(desc) |
| 34 | + noerr(t, err) |
| 35 | + if write.WriteConcern != nil { |
| 36 | + t.Error("write concern should be omitted from write command, but is present") |
| 37 | + } |
| 38 | + }) |
| 39 | +} |
0 commit comments