Routines for HTTP interface testing in Rust.
Build the development container.
sh
vagrant up
Connect to the development container.
sh
vagrant ssh
sh
cargo rustdoc -- --document-private-items
```rust extern crate interfacetestshelpers;
use interfacetestshelpers::{ ClientHandler, ResponseHandler, HasBaseUrl, };
use reqwest::{ Client, Response, };
use std::collections::HashMap;
impl HasBaseUrl for Client {
/// Returns the service base URL.
///
/// # Returns:
///
/// the service base URL.
fn get_base_url(&self) -> &str {
"http://localhost:1234"
}
}
trait ResourceHandler {
fn post_resource(&self, json: &HashMap<&str, &str>) -> Response;
}
impl ResourceHandler for Client {
/// Example of "per resource implementation" method.
///
/// # Arguments:
///
/// `json` - the json data to send
fn post_resource(
&self,
json: &HashMap<&str, &str>,
) -> Response {
return self.post_json(
"/resource",
json,
);
}
}
fn testpostresource() {
let mut json: HashMap<&str, &str> = HashMap::new();
json.insert("key", "value");
let client = Client::new();
let response = client.post_resource(&json);
response.assert_201();
} ```
One thread only must be used:
rust
cargo test -- --test-threads=1