Merge pull request #11 from thijsc/travis

Add Travis config
pull/14/head
Thijs Cadier 9 years ago
commit 56453940b5

@ -0,0 +1,9 @@
language: rust
rust:
- stable
- beta
- nightly
services:
- mongodb
env:
- SKIP_SSL_CONNECTION_TESTS=true SKIP_EXTENDED_BULK_OPERATION_TESTS=true

@ -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.

@ -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<str> {
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());
}
}

@ -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

@ -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

Loading…
Cancel
Save