@@ -7,8 +7,11 @@ use serde::Deserialize;
7
7
use crate :: {
8
8
bson:: { doc, Bson , Document } ,
9
9
error:: Result ,
10
- options:: { AggregateOptions , CreateCollectionOptions } ,
11
- test:: { util:: TestClient , LOCK } ,
10
+ options:: { AggregateOptions , CreateCollectionOptions , IndexOptionDefaults } ,
11
+ test:: {
12
+ util:: { CommandEvent , EventClient , TestClient } ,
13
+ LOCK ,
14
+ } ,
12
15
Database ,
13
16
} ;
14
17
@@ -318,3 +321,55 @@ async fn db_aggregate_disk_use() {
318
321
. await
319
322
. expect ( "aggregate with disk use should succeed" ) ;
320
323
}
324
+
325
+ #[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
326
+ #[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
327
+ #[ function_name:: named]
328
+ async fn create_index_options_defaults ( ) {
329
+ let defaults = IndexOptionDefaults {
330
+ storage_engine : doc ! { "wiredTiger" : doc! { } } ,
331
+ } ;
332
+ index_option_defaults_test ( Some ( defaults) , function_name ! ( ) ) . await ;
333
+ }
334
+
335
+ #[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
336
+ #[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
337
+ #[ function_name:: named]
338
+ async fn create_index_options_defaults_not_specified ( ) {
339
+ index_option_defaults_test ( None , function_name ! ( ) ) . await ;
340
+ }
341
+
342
+ async fn index_option_defaults_test ( defaults : Option < IndexOptionDefaults > , name : & str ) {
343
+ let _guard = LOCK . run_concurrently ( ) . await ;
344
+
345
+ let client = EventClient :: new ( ) . await ;
346
+ let db = client. database ( name) ;
347
+
348
+ let options = CreateCollectionOptions :: builder ( )
349
+ . index_option_defaults ( defaults. clone ( ) )
350
+ . build ( ) ;
351
+ db. create_collection ( name, options) . await . unwrap ( ) ;
352
+ db. drop ( None ) . await . unwrap ( ) ;
353
+
354
+ let events = client. command_events . read ( ) . unwrap ( ) ;
355
+ let mut iter = events. iter ( ) . filter_map ( |event| match event {
356
+ CommandEvent :: CommandStartedEvent ( event) => {
357
+ if event. command_name == "create" {
358
+ Some ( event)
359
+ } else {
360
+ None
361
+ }
362
+ }
363
+ _ => None ,
364
+ } ) ;
365
+
366
+ let event = iter. next ( ) . unwrap ( ) ;
367
+ let event_defaults = match event. command . get_document ( "indexOptionDefaults" ) {
368
+ Ok ( defaults) => Some ( IndexOptionDefaults {
369
+ storage_engine : defaults. get_document ( "storageEngine" ) . unwrap ( ) . clone ( ) ,
370
+ } ) ,
371
+ Err ( _) => None ,
372
+ } ;
373
+ assert_eq ! ( event_defaults, defaults) ;
374
+ assert ! ( iter. next( ) . is_none( ) ) ;
375
+ }
0 commit comments