You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
Rust
58 lines
1.7 KiB
Rust
use mongo_driver::uri::Uri;
|
|
use mongo_driver::client::ClientPool;
|
|
|
|
#[test]
|
|
fn test_command() {
|
|
let uri = Uri::new("mongodb://localhost:27017/").unwrap();
|
|
let pool = ClientPool::new(uri, None);
|
|
let client = pool.pop();
|
|
let database = client.get_database("rust_test");
|
|
|
|
let command = doc! { "ping" => 1 };
|
|
|
|
let result = database.command(command, None).unwrap().next().unwrap().unwrap();
|
|
assert!(result.contains_key("ok"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_command_simple() {
|
|
let uri = Uri::new("mongodb://localhost:27017/").unwrap();
|
|
let pool = ClientPool::new(uri, None);
|
|
let client = pool.pop();
|
|
let database = client.get_database("rust_test");
|
|
|
|
let command = doc! { "ping" => 1 };
|
|
|
|
let result = database.command_simple(command, None).unwrap();
|
|
assert!(result.contains_key("ok"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_get_collection_and_name() {
|
|
let uri = Uri::new("mongodb://localhost:27017/").unwrap();
|
|
let pool = ClientPool::new(uri, None);
|
|
let client = pool.pop();
|
|
let database = client.get_database("rust_test");
|
|
|
|
assert_eq!("rust_test", database.get_name().to_mut());
|
|
|
|
let collection = database.get_collection("items");
|
|
assert_eq!("items", collection.get_name().to_mut());
|
|
}
|
|
|
|
#[test]
|
|
fn test_create_collection() {
|
|
let uri = Uri::new("mongodb://localhost:27017/").unwrap();
|
|
let pool = ClientPool::new(uri, None);
|
|
let client = pool.pop();
|
|
let database = client.get_database("rust_test");
|
|
database.get_collection("created_collection").drop().unwrap_or(());
|
|
|
|
let collection = database.create_collection(
|
|
"created_collection",
|
|
None
|
|
).unwrap();
|
|
|
|
assert_eq!("created_collection", collection.get_name().to_mut());
|
|
}
|