3 releases

0.3.4 Dec 18, 2019
0.3.3 Oct 10, 2019
0.3.2 Oct 10, 2019

#1142 in HTTP server

GPL-3.0 license

40KB
808 lines

Anneal

Anneal is a testing framework for Iron. It was desgined to allow testing components in isolation.

Example

use anneal::RequestBuilder;

fn main() {
    RequestBuilder::new(Method::Post, "https://127.0.0.1:8080/")
        .set_body("this is a body".into())
        .request(|mut req| {
			// test code here

            let mut s = String::new();
            req.body.read_to_string(&mut s).unwrap();
            assert_eq!(s, "this is a body");
        })
}

Features

cookies: adds a method to add a CookieJar from cookie to the request

json: adds a method to set the body to a json object via serde_json

jsonapi: adds a pair of methods for adding json-api documents to a request body


lib.rs:

A crate for testing Iron handlers and middleware

This crate generates requests in a very similar way to iron-test but allows the testing of individual middleware in isolation.

Example

#[test]
fn anneal_demo() {
    RequestBuilder::new(Method::Post, "https://127.0.0.1:8080/")
        .set_header(headers::ContentType::json())
        .set_body("this is a body".into())
        .request(|mut req| {
            let mut headers = Headers::new();
            headers.set(headers::ContentLength(14));
            headers.set(headers::UserAgent("anneal".into()));
            headers.set(headers::ContentType::json());
            assert_eq!(req.headers, headers);
            assert_eq!(req.method,  Method::Post);
            assert_eq!(req.url, "https://127.0.0.1:8080/".parse().unwrap());
            assert_eq!(req.local_addr, "127.0.0.1:8080".parse().unwrap());
            assert_eq!(req.remote_addr, "127.0.0.1:3000".parse().unwrap());
            assert_eq!(req.version, HttpVersion::Http11);

            let mut s = String::new();
            req.body.read_to_string(&mut s).unwrap();
            assert_eq!(s, "this is a body");
        })
}

Features

cookies: adds a method to add a CookieJar from cookie to the request

json: adds a method to set the body to a json object via serde_json

jsonapi: adds a pair of methods for adding json-api documents to a request body

Dependencies

~5MB
~121K SLoC