Add integration test to prove the pudding (run with cargo test --features unstable).
@@ -88,3 +88,34 @@ fn nested_middleware() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
assert_eq!(&*buf, &*b"/bar");
}
+
+#[test]
+fn nested_with_different_state() {
+ let mut outer = tide::new();
+ let mut inner = tide::with_state(42);
+ inner.at("/").get(|req: tide::Request<i32>| async move {
+ let num = req.state();
+ format!("the number is {}", num)
+ });
+ outer.at("/").get(|_| async move { "Hello, world!" });
+ outer
+ .at("/foo")
+ .strip_prefix()
+ .get(inner.into_http_service());
+
+ let mut server = make_server(outer.into_http_service()).unwrap();
+
+ let mut buf = Vec::new();
+ let req = http::Request::get("/foo").body(Body::empty()).unwrap();
+ let res = server.simulate(req).unwrap();
+ assert_eq!(res.status(), 200);
+ block_on(res.into_body().read_to_end(&mut buf)).unwrap();
+ assert_eq!(&*buf, &*b"the number is 42");
+
+ buf.clear();
+ let req = http::Request::get("/").body(Body::empty()).unwrap();
+ let res = server.simulate(req).unwrap();
+ assert_eq!(res.status(), 200);
+ block_on(res.into_body().read_to_end(&mut buf)).unwrap();
+ assert_eq!(&*buf, &*b"Hello, world!");
+}
