#http-interface #testing #testing-http #routines #helper #response #client

interface-tests-helpers

HTTP interface tests helpers and routines

2 unstable releases

Uses old Rust 2015

0.2.0 Jun 24, 2019
0.1.0 Mar 24, 2018

#17 in #http-interface

MIT license

16KB
345 lines

Build Status

Current Crates.io Version

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

~19MB
~423K SLoC