@@ -1362,3 +1362,75 @@ func TestAggregateMultiFieldJoin(t *testing.T) {
13621362 require .Contains (t , result .Rows [0 ], `"variation"` )
13631363 require .NotContains (t , result .Rows [0 ], `"_id"` )
13641364}
1365+
1366+ func TestGetCollectionInfos (t * testing.T ) {
1367+ client , cleanup := setupTestContainer (t )
1368+ defer cleanup ()
1369+
1370+ ctx := context .Background ()
1371+
1372+ // Create collections by inserting documents
1373+ _ , err := client .Database ("testdb" ).Collection ("users" ).InsertOne (ctx , bson.M {"name" : "alice" })
1374+ require .NoError (t , err )
1375+ _ , err = client .Database ("testdb" ).Collection ("orders" ).InsertOne (ctx , bson.M {"item" : "book" })
1376+ require .NoError (t , err )
1377+
1378+ gc := gomongo .NewClient (client )
1379+
1380+ // Test without filter - should return all collections
1381+ result , err := gc .Execute (ctx , "testdb" , "db.getCollectionInfos()" )
1382+ require .NoError (t , err )
1383+ require .NotNil (t , result )
1384+ require .Equal (t , 2 , result .RowCount )
1385+
1386+ // Verify that results contain collection info structure
1387+ for _ , row := range result .Rows {
1388+ require .Contains (t , row , `"name"` )
1389+ require .Contains (t , row , `"type"` )
1390+ }
1391+ }
1392+
1393+ func TestGetCollectionInfosWithFilter (t * testing.T ) {
1394+ client , cleanup := setupTestContainer (t )
1395+ defer cleanup ()
1396+
1397+ ctx := context .Background ()
1398+
1399+ // Create collections by inserting documents
1400+ _ , err := client .Database ("testdb" ).Collection ("users" ).InsertOne (ctx , bson.M {"name" : "alice" })
1401+ require .NoError (t , err )
1402+ _ , err = client .Database ("testdb" ).Collection ("orders" ).InsertOne (ctx , bson.M {"item" : "book" })
1403+ require .NoError (t , err )
1404+
1405+ gc := gomongo .NewClient (client )
1406+
1407+ // Test with filter - should return only matching collection
1408+ result , err := gc .Execute (ctx , "testdb" , `db.getCollectionInfos({ name: "users" })` )
1409+ require .NoError (t , err )
1410+ require .NotNil (t , result )
1411+ require .Equal (t , 1 , result .RowCount )
1412+
1413+ // Verify that the returned collection is "users"
1414+ require .Contains (t , result .Rows [0 ], `"name": "users"` )
1415+ require .Contains (t , result .Rows [0 ], `"type": "collection"` )
1416+ }
1417+
1418+ func TestGetCollectionInfosEmptyResult (t * testing.T ) {
1419+ client , cleanup := setupTestContainer (t )
1420+ defer cleanup ()
1421+
1422+ ctx := context .Background ()
1423+
1424+ // Create a collection
1425+ _ , err := client .Database ("testdb" ).Collection ("users" ).InsertOne (ctx , bson.M {"name" : "alice" })
1426+ require .NoError (t , err )
1427+
1428+ gc := gomongo .NewClient (client )
1429+
1430+ // Test with filter that matches no collections
1431+ result , err := gc .Execute (ctx , "testdb" , `db.getCollectionInfos({ name: "nonexistent" })` )
1432+ require .NoError (t , err )
1433+ require .NotNil (t , result )
1434+ require .Equal (t , 0 , result .RowCount )
1435+ require .Empty (t , result .Rows )
1436+ }
0 commit comments