diff --git a/src/router.rs b/src/router.rs index 941c9dd..9999ab5 100644 --- a/src/router.rs +++ b/src/router.rs @@ -22,5 +22,34 @@ impl Router { None => respond_not_found(request), } } + + pub fn add_route(&mut self, route: &str, route_function: fn(Request)) { + self.routes.insert(route.to_string(), route_function); + } +} + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + + use tiny_http::Request; + + use super::Router; + + #[test] + fn test_add_route() { + let mut router = Router::new(); + + fn test_route(_request: Request) { + + } + + router.add_route("/test", test_route as fn(Request)); + + let mut expected = HashMap::new(); + expected.insert("/test".to_string(), test_route as fn(Request)); + + assert_eq!(router.routes, expected); + } }