tokiotest-httpserver

Crates.iotokiotest-httpserver
lib.rstokiotest-httpserver
version0.2.1
sourcesrc
created_at2022-03-03 16:30:46.105008
updated_at2022-03-16 07:20:58.721361
descriptionA simple http server to make unit/integration tests
homepage
repositoryhttps://github.com/iroco-co/tokiotest-httpserver
max_upload_size
id542953
size15,252
Bruno Thomas (bamthomas)

documentation

README

tokiotest-httpserver CircleCI

A small test server utility to run http request against.

parallel use

The test context instantiates a new server with a random port between 12300 and 12400. The test will use this port :

use test_context::{AsyncTestContext, test_context};
use hyper::{Uri, StatusCode, Client};
use tokiotest_httpserver::handler::{HandlerBuilder};
use tokiotest_httpserver::HttpTestContext;

#[test_context(HttpTestContext)]
#[tokio::test]
async fn test_get_respond_200(ctx: &mut HttpTestContext) {
    ctx.add(HandlerBuilder::new("/ok").status_code(StatusCode::OK).build());

    let resp = Client::new().get(ctx.uri("/ok")).await.unwrap();

    assert_eq!(200, resp.status());
}

At the end of the test, the port is released and can be used in another test.

serial use

It is also possible to use it with a sequential workflow. You just have to include the serial_test crate, and add the annotation.

With serial workflow you can choose to use a fixed port for the http test server by setting the environment variable TOKIOTEST_HTTP_PORT to the desired port.

See for example test_serial.

Commit count: 30

cargo fmt