@@ -15,6 +15,7 @@ import (
1515 "go.mongodb.org/mongo-driver/mongo"
1616 "go.mongodb.org/mongo-driver/mongo/integration/mtest"
1717 "go.mongodb.org/mongo-driver/mongo/options"
18+ "go.mongodb.org/mongo-driver/mongo/writeconcern"
1819)
1920
2021type index struct {
@@ -138,26 +139,54 @@ func TestIndexView(t *testing.T) {
138139 })
139140 })
140141 mt .Run ("create many" , func (mt * mtest.T ) {
141- iv := mt .Coll .Indexes ()
142- indexNames , err := iv .CreateMany (mtest .Background , []mongo.IndexModel {
143- {
144- Keys : bson.D {{"foo" , - 1 }},
145- },
146- {
147- Keys : bson.D {{"bar" , 1 }, {"baz" , - 1 }},
148- },
149- })
150- assert .Nil (mt , err , "CreateMany error: %v" , err )
151- assert .Equal (mt , 2 , len (indexNames ), "expected 2 index names, got %v" , len (indexNames ))
142+ mt .Run ("success" , func (mt * mtest.T ) {
143+ iv := mt .Coll .Indexes ()
144+ indexNames , err := iv .CreateMany (mtest .Background , []mongo.IndexModel {
145+ {
146+ Keys : bson.D {{"foo" , - 1 }},
147+ },
148+ {
149+ Keys : bson.D {{"bar" , 1 }, {"baz" , - 1 }},
150+ },
151+ })
152+ assert .Nil (mt , err , "CreateMany error: %v" , err )
153+ assert .Equal (mt , 2 , len (indexNames ), "expected 2 index names, got %v" , len (indexNames ))
152154
153- verifyIndexExists (mt , iv , index {
154- Key : map [string ]int {"foo" : - 1 },
155- Name : indexNames [0 ],
156- })
157- verifyIndexExists (mt , iv , index {
158- Key : map [string ]int {"bar" : 1 , "baz" : - 1 },
159- Name : indexNames [1 ],
155+ verifyIndexExists (mt , iv , index {
156+ Key : map [string ]int {"foo" : - 1 },
157+ Name : indexNames [0 ],
158+ })
159+ verifyIndexExists (mt , iv , index {
160+ Key : map [string ]int {"bar" : 1 , "baz" : - 1 },
161+ Name : indexNames [1 ],
162+ })
160163 })
164+ wc := writeconcern .New (writeconcern .W (1 ))
165+ mt .RunOpts ("uses writeconcern" ,
166+ mtest .NewOptions ().CollectionOptions (options .Collection ().SetWriteConcern (wc )),
167+ func (mt * mtest.T ) {
168+ iv := mt .Coll .Indexes ()
169+ _ , err := iv .CreateMany (mtest .Background , []mongo.IndexModel {
170+ {
171+ Keys : bson.D {{"foo" , - 1 }},
172+ },
173+ {
174+ Keys : bson.D {{"bar" , 1 }, {"baz" , - 1 }},
175+ },
176+ })
177+ assert .Nil (mt , err , "CreateMany error: %v" , err )
178+
179+ evt := mt .GetStartedEvent ()
180+ assert .NotNil (mt , evt , "expected CommandStartedEvent, got nil" )
181+
182+ assert .Equal (mt , "createIndexes" , evt .CommandName , "command name mismatch; expected createIndexes, got %s" , evt .CommandName )
183+
184+ actual , err := evt .Command .LookupErr ("writeConcern" , "w" )
185+ assert .Nil (mt , err , "error getting writeConcern.w: %s" , err )
186+
187+ wcVal := numberFromValue (mt , actual )
188+ assert .Equal (mt , int64 (1 ), wcVal , "expected writeConcern to be 1, got: %v" , wcVal )
189+ })
161190 })
162191 mt .Run ("drop one" , func (mt * mtest.T ) {
163192 iv := mt .Coll .Indexes ()
0 commit comments