From 1e2ede61d9ec82fd330ba69da8928d1496cbb5fc Mon Sep 17 00:00:00 2001 From: shellfly Date: Sun, 29 Jan 2023 11:23:54 +0800 Subject: [PATCH] chore: bump version to 0.3.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- tests/test.rs | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72ad568..305bad1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -764,7 +764,7 @@ dependencies = [ [[package]] name = "haro" -version = "0.2.0" +version = "0.3.0" dependencies = [ "cookie", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 40366de..3adbc3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "haro" -version = "0.2.0" +version = "0.3.0" edition = "2021" description = "A simple and synchronous web framework written in and for Rust" license = "MIT OR Apache-2.0" diff --git a/tests/test.rs b/tests/test.rs index eb7e2ea..913a4d7 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,4 +1,4 @@ -use haro::{db, middleware, Application, DynHandler, Request, Response}; +use haro::{db, middleware, Application, DynHandler, Handler, Request, Response}; use http::StatusCode; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -9,9 +9,13 @@ fn test_app() { db::SQLite::init("test.db"); let mut app = Application::new("0:8080"); + let hello_handler = HelloHandler { + name: "Haro".to_string(), + }; app.middleware(middleware::logging); app.middleware(my_middleware); app.route("/", index); + app.route_handler("/hello", hello_handler); app.route("/hello/:name", hello); app.route("/input", input); app.route("/sqlite", sqlite); @@ -19,6 +23,9 @@ fn test_app() { let res = app.request("get", "/", HashMap::new(), &Vec::new()); assert_eq!("Hello Haro".as_bytes(), res.body()); + let res = app.request("get", "/hello", HashMap::new(), &Vec::new()); + assert_eq!("Hello Haro".as_bytes(), res.body()); + let res = app.request("get", "/hello/world", HashMap::new(), &Vec::new()); assert_eq!("{\"name\":\"world\"}".as_bytes(), res.body()); @@ -37,6 +44,15 @@ struct Person { name: String, } +struct HelloHandler { + name: String, +} +impl Handler for HelloHandler { + fn call(&self, _: Request) -> Response { + Response::str(format!("Hello {}", self.name)) + } +} + fn index(_: Request) -> Response { Response::str("Hello Haro") }