Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
/ test-server-rs Public archive

server for integration tests in rust

License

Notifications You must be signed in to change notification settings

ChriFo/test-server-rs

Repository files navigation

(Integration) Test server

Build Status codecov

Usage

[dev-dependencies]
test-server = { git = "https://github.com/ChriFo/test-server-rs", tag = "0.9.1" }

HttpResponse and HttpRequest are re-exports from actix-web.

// start server at random port
let _ = test_server::new("127.0.0.1:0", test_server::HttpResponse::Ok).unwrap();

// start server at given port
let server = test_server::new("127.0.0.1:8080", |req: test_server::HttpRequest| {
    println!("{:#?}", req);
    test_server::HttpResponse::Ok().body("hello world")
}).unwrap();

// request against server
let _ = get_request(&server.url());

assert_eq!(1, server.requests.len());

// requests are Request from crate http (which is re-exported as http as well)
let last_request = server.requests.next().unwrap();

assert_eq!("GET", last_request.method());
assert_eq!("/", last_request.uri().path());
// body, headers and query params are also available

For more examples have a look at the tests.