|
1 | 1 | use crate::{
|
2 |
| - bson::doc, |
| 2 | + bson::{doc, Bson}, |
3 | 3 | cmap::{CommandResponse, StreamDescription},
|
4 | 4 | concern::WriteConcern,
|
5 | 5 | error::{ErrorKind, WriteFailure},
|
@@ -44,6 +44,36 @@ async fn build() {
|
44 | 44 | );
|
45 | 45 | }
|
46 | 46 |
|
| 47 | +#[cfg_attr(feature = "tokio-runtime", tokio::test)] |
| 48 | +#[cfg_attr(feature = "async-std-runtime", async_std::test)] |
| 49 | +async fn build_validator() { |
| 50 | + let query = doc! { "x": { "$gt": 1 } }; |
| 51 | + let op = Create::new( |
| 52 | + Namespace { |
| 53 | + db: "test_db".to_string(), |
| 54 | + coll: "test_coll".to_string(), |
| 55 | + }, |
| 56 | + Some(CreateCollectionOptions { |
| 57 | + validation: Some(query.clone()), |
| 58 | + ..Default::default() |
| 59 | + }), |
| 60 | + ); |
| 61 | + |
| 62 | + let description = StreamDescription::new_testing(); |
| 63 | + let cmd = op.build(&description).unwrap(); |
| 64 | + |
| 65 | + assert_eq!(cmd.name.as_str(), "create"); |
| 66 | + assert_eq!(cmd.target_db.as_str(), "test_db"); |
| 67 | + assert_eq!(cmd.read_pref.as_ref(), None); |
| 68 | + assert_eq!( |
| 69 | + cmd.body, |
| 70 | + doc! { |
| 71 | + "create": "test_coll", |
| 72 | + "validator": Bson::Document(query) |
| 73 | + } |
| 74 | + ); |
| 75 | +} |
| 76 | + |
47 | 77 | #[cfg_attr(feature = "tokio-runtime", tokio::test)]
|
48 | 78 | #[cfg_attr(feature = "async-std-runtime", async_std::test)]
|
49 | 79 | async fn handle_success() {
|
|
0 commit comments