@@ -18,6 +18,17 @@ var wc2 = writeconcern.New(writeconcern.W(20))
18
18
var rpPrimary = readpref .Primary ()
19
19
var rpSeconadary = readpref .Secondary ()
20
20
21
+ func requireCollectionEqual (t * testing.T , expected * Collection , actual * Collection ) {
22
+ switch {
23
+ case expected .ReadConcern != actual .ReadConcern :
24
+ t .Errorf ("read concerns don't match" )
25
+ case expected .WriteConcern != actual .WriteConcern :
26
+ t .Errorf ("write concerns don't match" )
27
+ case expected .ReadPreference != actual .ReadPreference :
28
+ t .Errorf ("read preferences don't match" )
29
+ }
30
+ }
31
+
21
32
func createNestedBundle1 (t * testing.T ) * CollectionBundle {
22
33
nested := BundleCollection (ReadConcern (rcMajority ))
23
34
testhelpers .RequireNotNil (t , nested , "nested bundle was nil" )
@@ -60,7 +71,7 @@ func createNestedBundle3(t *testing.T) *CollectionBundle {
60
71
return outer
61
72
}
62
73
63
- func TestDbOpt (t * testing.T ) {
74
+ func TestCollectionOpt (t * testing.T ) {
64
75
nilBundle := BundleCollection ()
65
76
var nilDb = & Collection {}
66
77
@@ -95,11 +106,27 @@ func TestDbOpt(t *testing.T) {
95
106
WriteConcern : wc1 ,
96
107
}
97
108
109
+ t .Run ("TestAll" , func (t * testing.T ) {
110
+ opts := []Option {
111
+ ReadConcern (rcLocal ),
112
+ WriteConcern (wc1 ),
113
+ ReadPreference (rpPrimary ),
114
+ }
115
+
116
+ db , err := BundleCollection (opts ... ).Unbundle ()
117
+ testhelpers .RequireNil (t , err , "got non-nil error from unbundle: %s" , err )
118
+ requireCollectionEqual (t , db , & Collection {
119
+ ReadConcern : rcLocal ,
120
+ WriteConcern : wc1 ,
121
+ ReadPreference : rpPrimary ,
122
+ })
123
+ })
124
+
98
125
t .Run ("Unbundle" , func (t * testing.T ) {
99
126
var cases = []struct {
100
- name string
101
- bundle * CollectionBundle
102
- db * Collection
127
+ name string
128
+ bundle * CollectionBundle
129
+ collection * Collection
103
130
}{
104
131
{"NilBundle" , nilBundle , nilDb },
105
132
{"Bundle1" , bundle1 , bundle1Db },
@@ -111,15 +138,15 @@ func TestDbOpt(t *testing.T) {
111
138
112
139
for _ , tc := range cases {
113
140
t .Run (tc .name , func (t * testing.T ) {
114
- db , err := tc .bundle .Unbundle ()
141
+ collection , err := tc .bundle .Unbundle ()
115
142
testhelpers .RequireNil (t , err , "err unbundling db: %s" , err )
116
143
117
144
switch {
118
- case db .ReadConcern != tc .db .ReadConcern :
145
+ case collection .ReadConcern != tc .collection .ReadConcern :
119
146
t .Errorf ("read concerns don't match" )
120
- case db .WriteConcern != tc .db .WriteConcern :
147
+ case collection .WriteConcern != tc .collection .WriteConcern :
121
148
t .Errorf ("write concerns don't match" )
122
- case db .ReadPreference != tc .db .ReadPreference :
149
+ case collection .ReadPreference != tc .collection .ReadPreference :
123
150
t .Errorf ("read preferences don't match" )
124
151
}
125
152
})
0 commit comments