...

Source file src/go.mongodb.org/mongo-driver/mongo/options/changestreamoptions_test.go

Documentation: go.mongodb.org/mongo-driver/mongo/options

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

View as plain text