Struct couchdb::testing::FakeServer
[−]
[src]
pub struct FakeServer { /* fields omitted */ }
FakeServer
manages a CouchDB server process for application testing.
Summary
FakeServer
is an RAII-wrapper for an external CouchDB server process useful for testing.The external CouchDB process's underlying storage persists to the system's default temporary directory (e.g.,
/tmp
) and is deleted when theFakeServer
instance drops.
Remarks
FakeServer
is a fake, not a mock, meaning an application may use it to
send HTTP requests to a real CouchDB server and receive real responses.
Consequently, this means that CouchDB must be installed on the local machine
in order to use FakeServer
.
The CouchDB server will open an unused port on the local machine. The
application may obtain the server's exact address via the FakeServer::url
method.
The CouchDB server remains up and running for the lifetime of the
FakeServer
instance. When the instance drops, the server shuts down and
all of its data are deleted.
Example
extern crate couchdb; extern crate reqwest; let server_url = { let server = match couchdb::testing::FakeServer::new() { Ok(x) => x, Err(e) => { println!("Is CouchDB installed locally? ({})", e); return; } }; let mut response = reqwest::get(server.url()).unwrap(); assert!(response.status().is_success()); let root: couchdb::Root = response.json().unwrap(); println!("CouchDB welcome message: {}", root.couchdb); server.url().to_string() // Server shuts down when `server` goes out of scope. }; // The server is now shut down, so the client request fails. reqwest::get(&server_url).unwrap_err();