@@ -12,11 +12,30 @@ import (
12
12
13
13
"github.com/mongodb/mongo-go-driver/bson"
14
14
"github.com/mongodb/mongo-go-driver/internal/testutil"
15
+ "github.com/mongodb/mongo-go-driver/mongo/options"
15
16
"github.com/mongodb/mongo-go-driver/x/bsonx"
17
+ "github.com/mongodb/mongo-go-driver/x/mongo/driver"
18
+ "github.com/mongodb/mongo-go-driver/x/mongo/driver/session"
19
+ "github.com/mongodb/mongo-go-driver/x/mongo/driver/uuid"
16
20
"github.com/mongodb/mongo-go-driver/x/network/command"
17
21
"github.com/mongodb/mongo-go-driver/x/network/description"
18
22
)
19
23
24
+ func runCommand (t * testing.T , cmd command.ListIndexes , opts ... * options.ListIndexesOptions ) (command.Cursor , error ) {
25
+ clientID , err := uuid .New ()
26
+ noerr (t , err )
27
+
28
+ return driver .ListIndexes (
29
+ context .Background (),
30
+ cmd ,
31
+ testutil .Topology (t ),
32
+ description .WriteSelector (),
33
+ clientID ,
34
+ & session.Pool {},
35
+ opts ... ,
36
+ )
37
+ }
38
+
20
39
func TestCommandListIndexes (t * testing.T ) {
21
40
noerr := func (t * testing.T , err error ) {
22
41
// t.Helper()
@@ -25,16 +44,10 @@ func TestCommandListIndexes(t *testing.T) {
25
44
t .FailNow ()
26
45
}
27
46
}
28
- // TODO(GODRIVER-279) don't skip once legacy index enumeration implemented
29
- skipIfBelow32 (t )
30
47
31
48
t .Run ("InvalidDatabaseName" , func (t * testing.T ) {
32
- server , err := testutil .Topology (t ).SelectServer (context .Background (), description .WriteSelector ())
33
- noerr (t , err )
34
- conn , err := server .Connection (context .Background ())
35
- noerr (t , err )
36
49
ns := command.Namespace {DB : "ex" , Collection : "space" }
37
- cursor , err := ( & command.ListIndexes {NS : ns }). RoundTrip ( context . Background (), server . SelectedDescription (), server , conn )
50
+ cursor , err := runCommand ( t , command.ListIndexes {NS : ns })
38
51
noerr (t , err )
39
52
40
53
indexes := []string {}
@@ -58,12 +71,8 @@ func TestCommandListIndexes(t *testing.T) {
58
71
}
59
72
})
60
73
t .Run ("InvalidCollectionName" , func (t * testing.T ) {
61
- server , err := testutil .Topology (t ).SelectServer (context .Background (), description .WriteSelector ())
62
- noerr (t , err )
63
- conn , err := server .Connection (context .Background ())
64
- noerr (t , err )
65
74
ns := command.Namespace {DB : "ex" , Collection : testutil .ColName (t )}
66
- cursor , err := ( & command.ListIndexes {NS : ns }). RoundTrip ( context . Background (), server . SelectedDescription (), server , conn )
75
+ cursor , err := runCommand ( t , command.ListIndexes {NS : ns })
67
76
noerr (t , err )
68
77
69
78
indexes := []string {}
@@ -87,18 +96,14 @@ func TestCommandListIndexes(t *testing.T) {
87
96
}
88
97
})
89
98
t .Run ("SingleBatch" , func (t * testing.T ) {
90
- server , err := testutil .Topology (t ).SelectServer (context .Background (), description .WriteSelector ())
91
- noerr (t , err )
92
- conn , err := server .Connection (context .Background ())
93
- noerr (t , err )
94
99
testutil .AutoDropCollection (t )
95
100
testutil .AutoCreateIndexes (t , []string {"a" })
96
101
testutil .AutoCreateIndexes (t , []string {"b" })
97
102
testutil .AutoCreateIndexes (t , []string {"c" })
98
103
testutil .AutoCreateIndexes (t , []string {"d" , "e" })
99
104
100
105
ns := command .NewNamespace (dbName , testutil .ColName (t ))
101
- cursor , err := ( & command.ListIndexes {NS : ns }). RoundTrip ( context . Background (), server . SelectedDescription (), server , conn )
106
+ cursor , err := runCommand ( t , command.ListIndexes {NS : ns })
102
107
noerr (t , err )
103
108
104
109
indexes := []string {}
@@ -129,20 +134,13 @@ func TestCommandListIndexes(t *testing.T) {
129
134
}
130
135
})
131
136
t .Run ("MultipleBatch" , func (t * testing.T ) {
132
- server , err := testutil .Topology (t ).SelectServer (context .Background (), description .WriteSelector ())
133
- noerr (t , err )
134
- conn , err := server .Connection (context .Background ())
135
- noerr (t , err )
136
137
testutil .AutoDropCollection (t )
137
138
testutil .AutoCreateIndexes (t , []string {"a" })
138
139
testutil .AutoCreateIndexes (t , []string {"b" })
139
140
testutil .AutoCreateIndexes (t , []string {"c" })
140
141
141
142
ns := command .NewNamespace (dbName , testutil .ColName (t ))
142
- opts := []bsonx.Elem {
143
- {"batchSize" , bsonx .Int32 (1 )},
144
- }
145
- cursor , err := (& command.ListIndexes {NS : ns , Opts : opts }).RoundTrip (context .Background (), server .SelectedDescription (), server , conn )
143
+ cursor , err := runCommand (t , command.ListIndexes {NS : ns }, options .ListIndexes ().SetBatchSize (1 ))
146
144
noerr (t , err )
147
145
148
146
indexes := []string {}
0 commit comments