|
| 1 | +package options |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "go.mongodb.org/mongo-driver/internal/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestMergeChangeStreamOptions(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + |
| 12 | + fullDocumentP := func(x FullDocument) *FullDocument { return &x } |
| 13 | + int32P := func(x int32) *int32 { return &x } |
| 14 | + |
| 15 | + testCases := []struct { |
| 16 | + description string |
| 17 | + input []*ChangeStreamOptions |
| 18 | + want *ChangeStreamOptions |
| 19 | + }{ |
| 20 | + { |
| 21 | + description: "empty", |
| 22 | + input: []*ChangeStreamOptions{}, |
| 23 | + want: &ChangeStreamOptions{}, |
| 24 | + }, |
| 25 | + { |
| 26 | + description: "many ChangeStreamOptions with one configuration each", |
| 27 | + input: []*ChangeStreamOptions{ |
| 28 | + ChangeStream().SetFullDocumentBeforeChange(Required), |
| 29 | + ChangeStream().SetFullDocument(Required), |
| 30 | + ChangeStream().SetBatchSize(10), |
| 31 | + }, |
| 32 | + want: &ChangeStreamOptions{ |
| 33 | + FullDocument: fullDocumentP(Required), |
| 34 | + FullDocumentBeforeChange: fullDocumentP(Required), |
| 35 | + BatchSize: int32P(10), |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + description: "single ChangeStreamOptions with many configurations", |
| 40 | + input: []*ChangeStreamOptions{ |
| 41 | + ChangeStream(). |
| 42 | + SetFullDocumentBeforeChange(Required). |
| 43 | + SetFullDocument(Required). |
| 44 | + SetBatchSize(10), |
| 45 | + }, |
| 46 | + want: &ChangeStreamOptions{ |
| 47 | + FullDocument: fullDocumentP(Required), |
| 48 | + FullDocumentBeforeChange: fullDocumentP(Required), |
| 49 | + BatchSize: int32P(10), |
| 50 | + }, |
| 51 | + }, |
| 52 | + } |
| 53 | + |
| 54 | + for _, tc := range testCases { |
| 55 | + tc := tc // Capture range variable. |
| 56 | + |
| 57 | + t.Run(tc.description, func(t *testing.T) { |
| 58 | + t.Parallel() |
| 59 | + |
| 60 | + got := MergeChangeStreamOptions(tc.input...) |
| 61 | + assert.Equal(t, tc.want, got, "expected and actual ChangeStreamOptions are different") |
| 62 | + }) |
| 63 | + } |
| 64 | +} |
0 commit comments