@@ -39,15 +39,17 @@ var chunkSizeTests = []struct {
39
39
{"Bucket and upload set to different values" , options .GridFSBucket ().SetChunkSizeBytes (27 ), options .GridFSUpload ().SetChunkSizeBytes (31 )},
40
40
}
41
41
42
- func findIndex (ctx context.Context , t * testing.T , coll * mongo.Collection , keys ... string ) {
42
+ func findIndex (ctx context.Context , t * testing.T , coll * mongo.Collection , unique bool , keys ... string ) {
43
43
cur , err := coll .Indexes ().List (ctx )
44
44
if err != nil {
45
45
t .Fatalf ("Couldn't establish a cursor on the collection %v: %v" , coll .Name (), err )
46
46
}
47
47
foundIndex := false
48
48
for cur .Next (ctx ) {
49
49
if _ , err := cur .Current .LookupErr (keys ... ); err == nil {
50
- foundIndex = true
50
+ if uVal , err := cur .Current .LookupErr ("unique" ); (unique && err == nil && uVal .Boolean () == true ) || (! unique && (err != nil || uVal .Boolean () == false )) {
51
+ foundIndex = true
52
+ }
51
53
}
52
54
}
53
55
if ! foundIndex {
@@ -183,8 +185,8 @@ func TestGridFS(t *testing.T) {
183
185
findCtx , cancel := context .WithTimeout (ctx , 5 * time .Second )
184
186
defer cancel ()
185
187
186
- findIndex (findCtx , t , bucket .filesColl , "key" , "filename" )
187
- findIndex (findCtx , t , bucket .chunksColl , "key" , "files_id" )
188
+ findIndex (findCtx , t , bucket .filesColl , false , "key" , "filename" )
189
+ findIndex (findCtx , t , bucket .chunksColl , true , "key" , "files_id" )
188
190
})
189
191
190
192
t .Run ("RoundTrip" , func (t * testing.T ) {
0 commit comments