restest

Black-box integration test for REST APIs in Rust.

This crate provides the [assert_api] macro that allows to declaratively test, given a certain request, that the response emitted by the server is correct.

Example

```rust

![feature(assert_matches)]

use serde::{Deserialize, Serialize};

restest::port! { 8080 }

restest::assertapi! { POST "/user", PostUser { yearofbirth: 2000, } => User { yearof_birth: 2000, .. } }

[derive(Debug, Serialize)]

struct PostUser { yearofbirth: usize, }

[derive(Debug, Deserialize)]

struct User { yearofbirth: usize, id: Uuid } ```

Writing tests

The [port] macro sets the port at which the request must be run.

The tests are written as normal Rust tests (ie: functions annotated with #[test]). As we're using asynchronous code, we must write async tests, perhaps using #[tokio::test].

More specifically, the [assert_api] macro can be used in order to query the server API and analyze its response.

Running tests

The server must be running in the background when cargo test is run.

Required toolchain

The nightly feature allows the [assert_api] macro to expand to nightly-specific code. This offers the following features:

These two features must be added at the crate root using the following two lines:

```rust

![feature(assert_matches)]

![feature(let_else)]

```

Code of Conduct

We have a Code of Conduct so as to create a more enjoyable community and work environment. Please see the CODEOFCONDUCT file for more details.

License

Licensed under either of

at your option.

Dual MIT/Apache2 is strictly more permissive