Skip to content

Instantly share code, notes, and snippets.

@BillBarnhill
Created September 10, 2020 02:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BillBarnhill/ca9bb3b58bdc57a632613546d070222e to your computer and use it in GitHub Desktop.
Save BillBarnhill/ca9bb3b58bdc57a632613546d070222e to your computer and use it in GitHub Desktop.
An example Tide unit test in Rust, with a Request and checked Response
#[cfg(test)]
mod tests {
#[async_std::test]
async fn index_page() -> tide::Result<()> {
use tide::http::{Url, Method, Request, Response};
let mut app = tide::new();
app.at("/").get(|_| async { Ok("Hello, world!") });
let url = Url::parse("https://example.com").unwrap();
let req = Request::new(Method::Get, url);
let mut res: Response = app.respond(req).await?;
assert_eq!("Hello, world", res.body_string().await?);
Ok(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment