@@ -13,10 +13,12 @@ import (
1313 "time"
1414
1515 "go.mongodb.org/mongo-driver/v2/bson"
16+ "go.mongodb.org/mongo-driver/v2/internal/assert"
1617 "go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
1718 "go.mongodb.org/mongo-driver/v2/internal/require"
1819 "go.mongodb.org/mongo-driver/v2/mongo"
1920 "go.mongodb.org/mongo-driver/v2/mongo/options"
21+ "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
2022)
2123
2224func TestSearchIndex (t * testing.T ) {
@@ -35,20 +37,21 @@ func TestSearchIndex(t *testing.T) {
3537 mt .Run ("search indexes with empty option" , func (mt * mtest.T ) {
3638 ctx := context .Background ()
3739
38- _ , err := mt .Coll .InsertMany (ctx , []any {
39- bson.M {
40- "string_field" : "test1 test1" ,
41- },
42- })
43- require .NoError (mt , err , "failed to insert" )
40+ expected := bson .Raw (bsoncore .NewDocumentBuilder ().
41+ AppendString ("mode" , "secondaryPreferred" ).
42+ Build ())
4443
45- _ , err = mt .Coll .SearchIndexes ().CreateOne (ctx , mongo.SearchIndexModel {
44+ _ , err : = mt .Coll .SearchIndexes ().CreateOne (ctx , mongo.SearchIndexModel {
4645 Definition : bson.D {
4746 {"mappings" , bson.D {
4847 {"dynamic" , true },
4948 }},
5049 },
5150 })
5251 require .NoError (mt , err , "failed to create index" )
52+ evt := mt .GetStartedEvent ()
53+ actual , ok := evt .Command .Lookup ("indexes" ).DocumentOK ()
54+ assert .True (mt , ok , "expected command %v to contain an indexes document" , evt .Command )
55+ assert .Equal (mt , expected , actual , "expected indexes document %v, got %v" , expected , actual )
5356 })
5457}
0 commit comments