https://github.com/iroco-co/tokiotest-httpserver
a small test utility to run http request against
https://github.com/iroco-co/tokiotest-httpserver
Last synced: about 2 months ago
JSON representation
a small test utility to run http request against
- Host: GitHub
- URL: https://github.com/iroco-co/tokiotest-httpserver
- Owner: iroco-co
- License: mit
- Created: 2022-02-15T21:56:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-09T07:43:54.000Z (almost 3 years ago)
- Last Synced: 2025-03-25T07:36:12.227Z (2 months ago)
- Language: Rust
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# tokiotest-httpserver [](https://circleci.com/gh/iroco-co/tokiotest-httpserver/tree/main)
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 :
```rust,no_run
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`](https://docs.rs/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](tests/test_serial.rs).