diff --git a/src/client.rs b/src/client.rs index 8c96bbc..d143425 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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 { diff --git a/src/uri.rs b/src/uri.rs index c6c30a9..0525d2f 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -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()) diff --git a/tests/client.rs b/tests/client.rs index 3aa2374..21a4f31 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -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(); diff --git a/tests/uri.rs b/tests/uri.rs index 800fb4a..a191ea9 100644 --- a/tests/uri.rs +++ b/tests/uri.rs @@ -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); +}