Implement partialeq for uri and add get_uri on pool

pull/4/head
Thijs Cadier 9 years ago
parent 86d3d180a0
commit 6be7ce71f5

@ -60,6 +60,11 @@ impl ClientPool {
}
}
/// Get a reference to this pool's Uri
pub fn get_uri(&self) -> &Uri {
&self.uri
}
/// Retrieve a client from the client pool, possibly blocking until one is available.
/// See: http://api.mongodb.org/c/current/mongoc_client_pool_pop.html
pub fn pop(&self) -> Client {

@ -59,6 +59,12 @@ impl Uri {
// TODO add various methods that are available on uri
}
impl PartialEq for Uri {
fn eq(&self, other: &Uri) -> bool {
self.as_str() == other.as_str()
}
}
impl fmt::Debug for Uri {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.as_str())

@ -8,7 +8,8 @@ use mongo_driver::client::{ClientPool,SslOptions};
#[test]
fn test_new_pool_and_pop_client() {
let uri = Uri::new("mongodb://localhost:27017/").unwrap();
let pool = ClientPool::new(uri, None);
let pool = ClientPool::new(uri.clone(), None);
assert_eq!(pool.get_uri(), &uri);
// Pop a client and get a database and collection
let client = pool.pop();

@ -22,3 +22,13 @@ fn test_get_database() {
let uri = Uri::new("mongodb://localhost:27017/db").unwrap();
assert_eq!("db", uri.get_database().unwrap());
}
#[test]
fn test_equality() {
let uri1 = Uri::new("mongodb://localhost:27017/").unwrap();
let uri2 = Uri::new("mongodb://localhost:27018/").unwrap();
assert_eq!(uri1, uri1.clone());
assert!(uri1 == uri1.clone());
assert!(uri1 != uri2);
}

Loading…
Cancel
Save