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.
76 lines
2.3 KiB
Rust
76 lines
2.3 KiB
Rust
use mongo_driver::client::{ClientPool,Uri};
|
|
|
|
#[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());
|
|
}
|
|
|
|
#[test]
|
|
fn test_has_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");
|
|
|
|
const COLL_NAME: &'static str = "created_collection2";
|
|
|
|
database.get_collection(COLL_NAME).drop().unwrap_or(());
|
|
|
|
let collection = database.create_collection(
|
|
COLL_NAME,
|
|
None
|
|
).unwrap();
|
|
|
|
assert_eq!(COLL_NAME, collection.get_name().to_mut());
|
|
assert!(database.has_collection(COLL_NAME).unwrap());
|
|
} |