2 unstable releases
Uses old Rust 2015
0.2.0 | Jun 24, 2019 |
---|---|
0.1.0 | Mar 24, 2018 |
#19 in #http-interface
16KB
345 lines
interface-tests-helpers
Routines for HTTP interface testing in Rust.
Table of contents
Development
Build the development container.
vagrant up
Connect to the development container.
vagrant ssh
Generate documentation
cargo rustdoc -- --document-private-items
Usage
Cargo.toml:
[dev-dependencies]
interface-tests-helpers = "*"
extern crate interface_tests_helpers;
use interface_tests_helpers::{
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,
);
}
}
#[test]
fn test_post_resource() {
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();
}
Tests
One thread only must be used:
cargo test -- --test-threads=1
Dependencies
~22MB
~452K SLoC