Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce an extension trait for testing servers #601

Merged
merged 1 commit into from
Jul 10, 2020

Conversation

jbr
Copy link
Member

@jbr jbr commented Jun 16, 2020

This is a first step in the direction of a superagent/supertest type testing utility for tide. Currently it just supports simple requests and is not exported for usage outside of tide, but the intent is that as it accumulates more features and stabilizes, it might eventually be public under a tide::testing namespace for tide apps to use.

// this:
    let req = Request::new(
        Method::Get,
        Url::parse("http://example.com/foo/echo").unwrap(),
    );
    let mut res: Response = app.respond(req).await.unwrap();

// becomes:
    let mut res = app.get("/foo/echo").await;

and

 // this:
    let req = http::Request::new(
        Method::Get,
        Url::parse("http://localhost/add_one/3").unwrap(),
    );
    let mut res: http::Response = app.respond(req).await.unwrap();
    assert_eq!(&res.body_string().await.unwrap(), "4");

// becomes:
    assert_eq!(app.get_body("/add_one/3").await, "4");

@jbr jbr mentioned this pull request Jun 16, 2020
@jbr jbr added the enhancement New feature or request label Jun 19, 2020
src/endpoint.rs Outdated Show resolved Hide resolved
Copy link
Member

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change generally seems nice for tests, maybe there's some detail I'm not able to think of but otherwise lgtm.

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jbr jbr force-pushed the server-testing-trait branch 2 times, most recently from b8f2444 to bea2861 Compare July 10, 2020 02:24
@Fishrock123
Copy link
Member

still lgtm

@jbr jbr merged commit 8f152aa into http-rs:master Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants