@@ -67,18 +67,18 @@ func TestIndexView_List(t *testing.T) {
67
67
cursor , err := indexView .List (context .Background ())
68
68
require .NoError (t , err )
69
69
70
- found := false
71
- var index = index {}
70
+ var found bool
71
+ var idx index
72
72
73
73
for cursor .Next (context .Background ()) {
74
- err := cursor .Decode (& index )
74
+ err := cursor .Decode (& idx )
75
75
require .NoError (t , err )
76
76
77
- require .Equal (t , expectedNS , index .NS )
77
+ require .Equal (t , expectedNS , idx .NS )
78
78
79
- if index .Name == "_id_" {
80
- require .Len (t , index .Key , 1 )
81
- require .Equal (t , 1 , index .Key ["_id" ])
79
+ if idx .Name == "_id_" {
80
+ require .Len (t , idx .Key , 1 )
81
+ require .Equal (t , 1 , idx .Key ["_id" ])
82
82
found = true
83
83
}
84
84
}
@@ -110,18 +110,63 @@ func TestIndexView_CreateOne(t *testing.T) {
110
110
cursor , err := indexView .List (context .Background ())
111
111
require .NoError (t , err )
112
112
113
- found := false
114
- var index = index {}
113
+ var found bool
114
+ var idx index
115
115
116
116
for cursor .Next (context .Background ()) {
117
- err := cursor .Decode (& index )
117
+ err := cursor .Decode (& idx )
118
118
require .NoError (t , err )
119
119
120
- require .Equal (t , expectedNS , index .NS )
120
+ require .Equal (t , expectedNS , idx .NS )
121
121
122
- if index .Name == indexName {
123
- require .Len (t , index .Key , 1 )
124
- require .Equal (t , - 1 , index .Key ["foo" ])
122
+ if idx .Name == indexName {
123
+ require .Len (t , idx .Key , 1 )
124
+ require .Equal (t , - 1 , idx .Key ["foo" ])
125
+ found = true
126
+ }
127
+ }
128
+ require .NoError (t , cursor .Err ())
129
+ require .True (t , found )
130
+ }
131
+
132
+ func TestIndexView_CreateOneWithIndexOptions (t * testing.T ) {
133
+ t .Parallel ()
134
+
135
+ if testing .Short () {
136
+ t .Skip ()
137
+ }
138
+
139
+ dbName , coll := getIndexableCollection (t )
140
+ expectedNS := fmt .Sprintf ("IndexView.%s" , dbName )
141
+ indexView := coll .Indexes ()
142
+
143
+ indexName , err := indexView .CreateOne (
144
+ context .Background (),
145
+ IndexModel {
146
+ Keys : bson .NewDocument (
147
+ bson .EC .Int32 ("foo" , - 1 ),
148
+ ),
149
+ Options : NewIndexOptionsBuilder ().Name ("testname" ).Build (),
150
+ },
151
+ )
152
+ require .NoError (t , err )
153
+ require .Equal (t , "testname" , indexName )
154
+
155
+ cursor , err := indexView .List (context .Background ())
156
+ require .NoError (t , err )
157
+
158
+ var found bool
159
+ var idx index
160
+
161
+ for cursor .Next (context .Background ()) {
162
+ err := cursor .Decode (& idx )
163
+ require .NoError (t , err )
164
+
165
+ require .Equal (t , expectedNS , idx .NS )
166
+
167
+ if idx .Name == indexName {
168
+ require .Len (t , idx .Key , 1 )
169
+ require .Equal (t , - 1 , idx .Key ["foo" ])
125
170
found = true
126
171
}
127
172
}
@@ -167,24 +212,24 @@ func TestIndexView_CreateMany(t *testing.T) {
167
212
168
213
fooFound := false
169
214
barBazFound := false
170
- var index = index {}
215
+ var idx index
171
216
172
217
for cursor .Next (context .Background ()) {
173
- err := cursor .Decode (& index )
218
+ err := cursor .Decode (& idx )
174
219
require .NoError (t , err )
175
220
176
- require .Equal (t , expectedNS , index .NS )
221
+ require .Equal (t , expectedNS , idx .NS )
177
222
178
- if index .Name == fooName {
179
- require .Len (t , index .Key , 1 )
180
- require .Equal (t , - 1 , index .Key ["foo" ])
223
+ if idx .Name == fooName {
224
+ require .Len (t , idx .Key , 1 )
225
+ require .Equal (t , - 1 , idx .Key ["foo" ])
181
226
fooFound = true
182
227
}
183
228
184
- if index .Name == barBazName {
185
- require .Len (t , index .Key , 2 )
186
- require .Equal (t , 1 , index .Key ["bar" ])
187
- require .Equal (t , - 1 , index .Key ["baz" ])
229
+ if idx .Name == barBazName {
230
+ require .Len (t , idx .Key , 2 )
231
+ require .Equal (t , 1 , idx .Key ["bar" ])
232
+ require .Equal (t , - 1 , idx .Key ["baz" ])
188
233
barBazFound = true
189
234
}
190
235
}
@@ -232,14 +277,14 @@ func TestIndexView_DropOne(t *testing.T) {
232
277
cursor , err := indexView .List (context .Background ())
233
278
require .NoError (t , err )
234
279
235
- var index = index {}
280
+ var idx index
236
281
237
282
for cursor .Next (context .Background ()) {
238
- err := cursor .Decode (& index )
283
+ err := cursor .Decode (& idx )
239
284
require .NoError (t , err )
240
285
241
- require .Equal (t , expectedNS , index .NS )
242
- require .NotEqual (t , indexNames [1 ], index .Name )
286
+ require .Equal (t , expectedNS , idx .NS )
287
+ require .NotEqual (t , indexNames [1 ], idx .Name )
243
288
}
244
289
require .NoError (t , cursor .Err ())
245
290
}
@@ -282,15 +327,15 @@ func TestIndexView_DropAll(t *testing.T) {
282
327
cursor , err := indexView .List (context .Background ())
283
328
require .NoError (t , err )
284
329
285
- var index = index {}
330
+ var idx index
286
331
287
332
for cursor .Next (context .Background ()) {
288
- err := cursor .Decode (& index )
333
+ err := cursor .Decode (& idx )
289
334
require .NoError (t , err )
290
335
291
- require .Equal (t , expectedNS , index .NS )
292
- require .NotEqual (t , indexNames [0 ], index .Name )
293
- require .NotEqual (t , indexNames [1 ], index .Name )
336
+ require .Equal (t , expectedNS , idx .NS )
337
+ require .NotEqual (t , indexNames [0 ], idx .Name )
338
+ require .NotEqual (t , indexNames [1 ], idx .Name )
294
339
}
295
340
require .NoError (t , cursor .Err ())
296
341
}
@@ -339,24 +384,24 @@ func TestIndexView_CreateIndexesOptioner(t *testing.T) {
339
384
340
385
fooFound := false
341
386
barBazFound := false
342
- var index = index {}
387
+ var idx index
343
388
344
389
for cursor .Next (context .Background ()) {
345
- err := cursor .Decode (& index )
390
+ err := cursor .Decode (& idx )
346
391
require .NoError (t , err )
347
392
348
- require .Equal (t , expectedNS , index .NS )
393
+ require .Equal (t , expectedNS , idx .NS )
349
394
350
- if index .Name == fooName {
351
- require .Len (t , index .Key , 1 )
352
- require .Equal (t , - 1 , index .Key ["foo" ])
395
+ if idx .Name == fooName {
396
+ require .Len (t , idx .Key , 1 )
397
+ require .Equal (t , - 1 , idx .Key ["foo" ])
353
398
fooFound = true
354
399
}
355
400
356
- if index .Name == barBazName {
357
- require .Len (t , index .Key , 2 )
358
- require .Equal (t , 1 , index .Key ["bar" ])
359
- require .Equal (t , - 1 , index .Key ["baz" ])
401
+ if idx .Name == barBazName {
402
+ require .Len (t , idx .Key , 2 )
403
+ require .Equal (t , 1 , idx .Key ["bar" ])
404
+ require .Equal (t , - 1 , idx .Key ["baz" ])
360
405
barBazFound = true
361
406
}
362
407
}
@@ -413,14 +458,14 @@ func TestIndexView_DropIndexesOptioner(t *testing.T) {
413
458
cursor , err := indexView .List (context .Background ())
414
459
require .NoError (t , err )
415
460
416
- var index = index {}
461
+ var idx index
417
462
418
463
for cursor .Next (context .Background ()) {
419
- err := cursor .Decode (& index )
464
+ err := cursor .Decode (& idx )
420
465
require .NoError (t , err )
421
- require .Equal (t , expectedNS , index .NS )
422
- require .NotEqual (t , indexNames [0 ], index .Name )
423
- require .NotEqual (t , indexNames [1 ], index .Name )
466
+ require .Equal (t , expectedNS , idx .NS )
467
+ require .NotEqual (t , indexNames [0 ], idx .Name )
468
+ require .NotEqual (t , indexNames [1 ], idx .Name )
424
469
}
425
470
require .NoError (t , cursor .Err ())
426
471
}
0 commit comments