grillon 0.3.0

Grillon offers an elegant and natural way to approach end-to-end HTTP API testing in Rust.
Documentation

Grillon

Crates.io docs.rs GitHub Workflow Status

Grillon offers an elegant and natural way to approach end-to-end HTTP API testing in Rust.

  • Elegant, intuitive and expressive API
  • Built-in testing functions
  • Extensible

Please note that the API is subject to a lot of changes until the v1.0.0.

Getting started

This example enables the optional diff feature and uses Tokio as asynchronous runtime. Generally, testing libs are used in unit or integration tests. You can declare grillon as a dev-dependency.

Add grillon to Cargo.toml

[dev-dependencies]
grillon = { version = "0.3.0", features = ["diff"] }
tokio = { version = "1", features = ["macros"] }

Then use grillon :

use grillon::{
    header::{HeaderValue, CONTENT_TYPE},
    json, Grillon, StatusCode, Result
};

#[tokio::test]
async fn end_to_end_test() -> Result<()> {
    Grillon::new("http://jsonplaceholder.typicode.com")?
        .post("posts")
        .payload(json!({
            "title": "foo",
            "body": "bar",
            "userId": 1
        }))
        .assert()
        .await
        .status_success()
        .assert_fn(|assert| {
            assert!(!assert.headers.is_empty());
            assert!(assert.status == StatusCode::CREATED);
            assert!(assert.json.is_some());

            println!("Json response : {:#?}", assert.json);
        })
        .status(StatusCode::CREATED)
        .headers_exist(vec![(
            CONTENT_TYPE,
            HeaderValue::from_static("application/json; charset=utf-8"),
        )])
        .body(json!({
            "id": 101,
        }));

    Ok(())
}