From c44f47ce6f504898f234dc192a20ef0c2988d4ac Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Fri, 18 Dec 2015 16:30:21 +0100 Subject: [PATCH 1/5] Add Travis config --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..17eded6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: rust +rust: + - stable + - beta + - nightly +services: + - mongodb +env: + - SKIP_SSL_CONNECTION_TESTS=true From 3cdd312cdfa058cc1919f142b5fd932321fd89f2 Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Fri, 18 Dec 2015 16:55:03 +0100 Subject: [PATCH 2/5] Convert bson json to String directly --- src/bsonc.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bsonc.rs b/src/bsonc.rs index e51a9cd..ace68ee 100644 --- a/src/bsonc.rs +++ b/src/bsonc.rs @@ -1,6 +1,5 @@ use std::ffi::CStr; use std::ptr; -use std::borrow::Cow; use std::fmt; use std::slice; use libc::c_void; @@ -64,12 +63,12 @@ impl Bsonc { Ok(document) } - pub fn as_json(&self) -> Cow { + pub fn as_json(&self) -> String { assert!(!self.inner.is_null()); let json_ptr = unsafe { bindings::bson_as_json(self.inner, ptr::null_mut()) }; assert!(!json_ptr.is_null()); let json_cstr = unsafe { CStr::from_ptr(json_ptr) }; - let out = String::from_utf8_lossy(json_cstr.to_bytes()); + let out = String::from_utf8_lossy(json_cstr.to_bytes()).into_owned(); unsafe { bindings::bson_free(json_ptr as *mut c_void); } out } @@ -111,9 +110,9 @@ mod tests { } #[test] - fn test_bsonc_from_and_as_json() { + fn test_bsonc_as_json() { let document = doc! { "key" => "value" }; let bsonc = super::Bsonc::from_document(&document).unwrap(); - assert_eq!("{ \"key\" : \"value\" }", bsonc.as_json()); + assert_eq!("{ \"key\" : \"value\" }".to_owned(), bsonc.as_json()); } } From 9c86079f87b8f8b1f92168a8e825daa4d6740083 Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Fri, 18 Dec 2015 17:02:21 +0100 Subject: [PATCH 3/5] Remove test of error message that can vary between MongoDB versions --- tests/cursor.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/cursor.rs b/tests/cursor.rs index 59cd2ba..7f4b0e3 100644 --- a/tests/cursor.rs +++ b/tests/cursor.rs @@ -53,10 +53,6 @@ fn test_tailing_cursor() { let failing_cursor = normal_collection.tail(doc!{}, None, None); let failing_result = failing_cursor.into_iter().next().unwrap(); assert!(failing_result.is_err()); - assert_eq!( - "MongoError (BsoncError: Query/Unknown - Unable to execute query: error processing query: ns=rust_test.not_capped limit=0 skip=0\nTree: $and\nSort: {}\nProj: {}\n tailable cursor requested on non capped collection)", - format!("{:?}", failing_result.err().unwrap()) - ); let document = doc! { "key_1" => "Value 1" }; // Insert a first document into the collection From 6f0fc9b5b963bbc9bc4fd7d835edc92b22f619d9 Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Sat, 19 Dec 2015 20:29:21 +0100 Subject: [PATCH 4/5] Skip extended bulk operation test on Travis --- .travis.yml | 2 +- tests/bulk_operation.rs | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17eded6..22316c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ rust: services: - mongodb env: - - SKIP_SSL_CONNECTION_TESTS=true + - SKIP_SSL_CONNECTION_TESTS=true SKIP_EXTENDED_BULK_OPERATION_TESTS=true diff --git a/tests/bulk_operation.rs b/tests/bulk_operation.rs index b9cdff0..ed7696c 100644 --- a/tests/bulk_operation.rs +++ b/tests/bulk_operation.rs @@ -1,3 +1,5 @@ +use std::env; + use bson; use mongo_driver::uri::Uri; @@ -19,11 +21,28 @@ fn test_execute_error() { } #[test] -fn test_insert_remove_replace_update() { +fn test_basics() { + let uri = Uri::new("mongodb://localhost:27017/").unwrap(); + let pool = ClientPool::new(uri, None); + let client = pool.pop(); + let collection = client.get_collection("rust_driver_test", "bulk_operation_basics"); + let bulk_operation = collection.create_bulk_operation(None); + + let document = doc! {"key_1" => "Value 1"}; + bulk_operation.insert(&document).unwrap(); + assert!(bulk_operation.execute().is_ok()); +} + +#[test] +fn test_insert_remove_replace_update_extended() { + if env::var("SKIP_EXTENDED_BULK_OPERATION_TESTS") == Ok("true".to_string()) { + return + } + let uri = Uri::new("mongodb://localhost:27017/").unwrap(); let pool = ClientPool::new(uri, None); let client = pool.pop(); - let mut collection = client.get_collection("rust_driver_test", "bulk_operation_insert"); + let mut collection = client.get_collection("rust_driver_test", "bulk_operation_extended"); collection.drop().unwrap_or(()); // Insert 5 documents From 6925118d15738cc9cb98e18d18152c7c79ec3ed4 Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Sat, 19 Dec 2015 20:41:22 +0100 Subject: [PATCH 5/5] Add Travis badge and tweak readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad02a8f..e20a58b 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Mongo Rust Driver +[![Build Status](https://travis-ci.org/thijsc/mongo-rust-driver.svg)](https://travis-ci.org/thijsc/mongo-rust-driver) + ## About Mongo Rust driver built on top of the [Mongo C driver](https://github.com/mongodb/mongo-c-driver). -This drivers aims to be a thin wrapper around the production-ready C driver, while providing a safe -and ergonomic Rust interface that handles all the gnarly usage details of the C driver for you. +This driver is a thin wrapper around the production-ready C driver that provides a safe and ergonomic Rust interface which handles all the gnarly usage details of the C driver for you. -Bson encoding and decoding is handled by the [bson crate](https://github.com/zonyitoo/bson-rs), the bindings -are based on generated bindings by [bindgen](https://github.com/crabtw/rust-bindgen). +Bson encoding and decoding is handled by the [bson crate](https://github.com/zonyitoo/bson-rs), the bindings are based on generated bindings by [bindgen](https://github.com/crabtw/rust-bindgen). The API should still be considered experimental, but I'm not expecting changes at the moment.