Skip to content

Fix tests/wildcard#518

Merged
yoshuawuyts merged 18 commits intohttp-rs:masterfrom
yusuke-ota:fix_test_wildcard
May 29, 2020
Merged

Fix tests/wildcard#518
yoshuawuyts merged 18 commits intohttp-rs:masterfrom
yusuke-ota:fix_test_wildcard

Conversation

@yusuke-ota
Copy link
Copy Markdown
Contributor

@yusuke-ota yusuke-ota commented May 19, 2020

Fix test/wildcard.rs
This PR is related to #509


This file used Crate "http_service" and "http_service_mock".
But Cargo.toml does not contain them.
So, I use "Request::new(Method::Get, "http://localhost/*")" and "Server::respond(req)" instead of them.

@yusuke-ota yusuke-ota changed the title Fix test/wildcard Fix tests/wildcard May 19, 2020
Copy link
Copy Markdown
Member

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

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

thank you

let mut res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"4");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think instead taking the body and converting it into a string and then into bytes, these assertions can be made more concise with

assert_eq!(&res.body_string().await.unwrap(), "4");

Copy link
Copy Markdown
Contributor Author

@yusuke-ota yusuke-ota May 23, 2020

Choose a reason for hiding this comment

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

Thank you for review.
This corrected at070fbe1 f8c41bc.

use tide::{http, Request};

async fn add_one(cx: Request<()>) -> Result<String, tide::Error> {
return match cx.param::<i64>("num") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this return keyword necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for review.
This corrected at 070fbe1.


async fn add_two(cx: Request<()>) -> Result<String, tide::Error> {
let one;
match cx.param::<i64>("one") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this might read more idiomatically if one and two were returned by the match expression instead of assigned inside of the match expression, and the error early-returning could might be accomplished with a .map_err and a ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for review.
This corrected at af3b75f.

Copy link
Copy Markdown
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, thank you!

@yoshuawuyts yoshuawuyts merged commit 55a0e95 into http-rs:master May 29, 2020
@yusuke-ota yusuke-ota deleted the fix_test_wildcard branch May 30, 2020 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants