1
1
use futures:: TryStreamExt ;
2
+ use tokio:: sync:: RwLockReadGuard ;
2
3
3
4
use crate :: {
4
5
bson:: { doc, Bson } ,
5
6
error:: Result ,
6
- options:: FindOptions ,
7
- test:: TestClient ,
7
+ options:: { ClientOptions , CursorType , FindOptions , ServerApi , ServerApiVersion } ,
8
+ test:: { TestClient , DEFAULT_URI , LOCK } ,
9
+ Client ,
8
10
Collection ,
9
11
} ;
10
12
@@ -1364,9 +1366,68 @@ async fn delete_examples(collection: &Collection) -> Result<()> {
1364
1366
Ok ( ( ) )
1365
1367
}
1366
1368
1369
+ #[ allow( unused_variables) ]
1370
+ #[ cfg( not( feature = "sync" ) ) ]
1371
+ async fn versioned_api_examples ( ) -> Result < ( ) > {
1372
+ let setup_client = TestClient :: new ( ) . await ;
1373
+ if setup_client. server_version_lt ( 4 , 9 ) {
1374
+ println ! ( "skipping versioned API examples due to unsupported server version" ) ;
1375
+ return Ok ( ( ) ) ;
1376
+ }
1377
+
1378
+ let uri = DEFAULT_URI . clone ( ) ;
1379
+ // Start 1. Declare an API version on a client
1380
+ let mut options = ClientOptions :: parse ( & uri) . await ?;
1381
+ let server_api = ServerApi :: builder ( )
1382
+ . version ( ServerApiVersion :: Version1 )
1383
+ . build ( ) ;
1384
+ options. server_api = Some ( server_api) ;
1385
+ let client = Client :: with_options ( options) ?;
1386
+ let cursor = client
1387
+ . database ( "versioned_api_example" )
1388
+ . collection ( "example" )
1389
+ . find ( None , None )
1390
+ . await ?;
1391
+ // End 1.
1392
+
1393
+ // Start 2. Strict option
1394
+ let mut options = ClientOptions :: parse ( & uri) . await ?;
1395
+ let server_api = ServerApi :: builder ( )
1396
+ . version ( ServerApiVersion :: Version1 )
1397
+ . strict ( true )
1398
+ . build ( ) ;
1399
+ options. server_api = Some ( server_api) ;
1400
+ let client = Client :: with_options ( options) ?;
1401
+
1402
+ let find_options = FindOptions :: builder ( )
1403
+ . cursor_type ( CursorType :: Tailable )
1404
+ . build ( ) ;
1405
+ let cursor = client
1406
+ . database ( "versioned_api_example" )
1407
+ . collection ( "example" )
1408
+ . find ( None , find_options)
1409
+ . await
1410
+ . expect_err ( "should fail" ) ;
1411
+ // End 2.
1412
+
1413
+ // Start 3. deprecationErrors option
1414
+ let mut options = ClientOptions :: parse ( & uri) . await ?;
1415
+ let server_api = ServerApi :: builder ( )
1416
+ . version ( ServerApiVersion :: Version1 )
1417
+ . deprecation_errors ( true )
1418
+ . build ( ) ;
1419
+ options. server_api = Some ( server_api) ;
1420
+ let client = Client :: with_options ( options) ?;
1421
+ // End 3.
1422
+
1423
+ Ok ( ( ) )
1424
+ }
1425
+
1367
1426
#[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
1368
1427
#[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
1369
1428
async fn test ( ) {
1429
+ let _guard: RwLockReadGuard < _ > = LOCK . run_concurrently ( ) . await ;
1430
+
1370
1431
let client = TestClient :: new ( ) . await ;
1371
1432
let coll = client
1372
1433
. database ( "documentation_examples" )
@@ -1383,4 +1444,5 @@ async fn test() {
1383
1444
projection_examples ( & coll) . await . unwrap ( ) ;
1384
1445
update_examples ( & coll) . await . unwrap ( ) ;
1385
1446
delete_examples ( & coll) . await . unwrap ( ) ;
1447
+ versioned_api_examples ( ) . await . unwrap ( ) ;
1386
1448
}
0 commit comments