【Rust日报】2023-09-06 Grillon - API 测试框架

2023-09-26 19:38:27 浏览数 (1)

Grillon - API 测试框架

  • 优雅、直观和富有表现力的 API
  • 内置测试功能
  • 支持扩展

用法:

代码语言:javascript复制
use grillon::{dsl::*, dsl::http::*, json, Grillon, StatusCode, Result};
use grillon::header::{HeaderValue, CONTENT_LENGTH, CONTENT_TYPE};

#[tokio::test]
async fn end_to_end_test() -> Result<()> {
    Grillon::new("https://jsonplaceholder.typicode.com")?
        .post("posts")
        .payload(json!({
            "title": "foo",
            "body": "bar",
            "userId": 1
        }))
        .assert()
        .await
        .status(is_success())
        .status(is(201))
        .response_time(is_less_than(700))
        .json_body(is(json!({
            "id": 101,
        })))
        .json_body(schema(json!({
            "properties": {
                "id": { "type": "number" }
            }
        })))
        .json_path("$.id", is(json!(101)))
        .headers(contains(vec![
            (
                CONTENT_TYPE,
                HeaderValue::from_static("application/json; charset=utf-8"),
            ),
            (CONTENT_LENGTH, HeaderValue::from_static("15")),
        ]))
        .assert_fn(|assert| {
            assert!(!assert.headers.is_empty());
            assert!(assert.status == StatusCode::CREATED);
            assert!(assert.json.is_some());

            println!("Json response : {:#?}", assert.json);
        });

    Ok(())
}

ReadMore:https://github.com/owlduty/grillon

qcd - 快速切换目录

qcd是一个Linux工具,有助于提高命令行的效率。

切换目录
代码语言:javascript复制
qcd ENTRY [-n]  Chdir to path with idx or alias ENTRY (w/o -n: adds work dir to stack)
qcd -o          (pop)  Chdir to top of stack, remove that entry from stack
添加或删除入口
代码语言:javascript复制
qcd -a PATH [-i IDX] [-s ALIAS]   Add PATH to database
qcd -p [-i IDX] [-s ALIAS]        Add current working directory to database
qcd -r ENTRY                      Remove row with idx or alias ENTRY
qcd -u                            (push) Add current working directory to (top of) stack

ReadMore:https://github.com/ClaasBontus/qcd_rs

0 人点赞