From a4f42961b1fd0822abd05dcbaa4006920fc1c054 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Wed, 19 Jan 2022 15:32:26 -0800 Subject: [PATCH] Move tested methods inside tests; cleans a few things up Signed-off-by: Erik Hollensbe --- src/router.rs | 85 +++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/router.rs b/src/router.rs index 07b1c2d..b87326e 100644 --- a/src/router.rs +++ b/src/router.rs @@ -80,47 +80,31 @@ impl Router { } mod tests { - use http::{Request, Response}; - use hyper::Body; - - use crate::{handler::Params, HTTPResult}; - - #[allow(dead_code)] - async fn handler_static( - req: Request, - _response: Option>, - _params: Params, - ) -> HTTPResult { - return Ok(( - req, - Some( - Response::builder() - .status(400) - .body(Body::from("hello, world".as_bytes()))?, - ), - )); - } - - #[allow(dead_code)] - async fn handler_dynamic( - req: Request, - _response: Option>, - params: Params, - ) -> HTTPResult { - return Ok(( - req, - Some(Response::builder().status(400).body(Body::from(format!( - "hello, {}", - *params.get("name").unwrap() - )))?), - )); - } - #[tokio::test] async fn test_route_dynamic() { + use http::{Method, Request, Response}; + use hyper::Body; + + use crate::{ + handler::{Handler, Params}, + HTTPResult, + }; + use super::Route; - use crate::handler::Handler; - use http::Method; + + async fn handler_dynamic( + req: Request, + _response: Option>, + params: Params, + ) -> HTTPResult { + return Ok(( + req, + Some(Response::builder().status(400).body(Body::from(format!( + "hello, {}", + *params.get("name").unwrap() + )))?), + )); + } let route = Route::new( Method::GET, @@ -184,9 +168,30 @@ mod tests { #[tokio::test] async fn test_route_static() { + use http::{Method, Request, Response}; + use hyper::Body; + + use crate::{ + handler::{Handler, Params}, + HTTPResult, + }; + use super::Route; - use crate::handler::Handler; - use http::Method; + + async fn handler_static( + req: Request, + _response: Option>, + _params: Params, + ) -> HTTPResult { + return Ok(( + req, + Some( + Response::builder() + .status(400) + .body(Body::from("hello, world".as_bytes()))?, + ), + )); + } let route = Route::new( Method::GET,