Skip to content

Commit f384d99

Browse files
committed
add a test for multiple request cookies
1 parent 5908a3d commit f384d99

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/cookies.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ use tide::{Request, Response, Server, StatusCode};
88
static COOKIE_NAME: &str = "testCookie";
99

1010
async fn retrieve_cookie(cx: Request<()>) -> tide::Result<String> {
11-
Ok(cx.cookie(COOKIE_NAME).unwrap().value().to_string())
11+
Ok(format!(
12+
"{} and also {}",
13+
cx.cookie(COOKIE_NAME).unwrap().value(),
14+
cx.cookie("secondTestCookie").unwrap().value()
15+
))
1216
}
1317

1418
async fn set_cookie(_req: Request<()>) -> tide::Result {
@@ -47,8 +51,11 @@ fn make_request(endpoint: &str) -> http_types::Response {
4751
http_types::Method::Get,
4852
format!("http://example.com{}", endpoint).parse().unwrap(),
4953
);
50-
req.insert_header(http_types::headers::COOKIE, "testCookie=RequestCookieValue")
51-
.unwrap();
54+
req.insert_header(
55+
http_types::headers::COOKIE,
56+
"testCookie=RequestCookieValue; secondTestCookie=OtherCookieValue",
57+
)
58+
.unwrap();
5259

5360
server.simulate(req).unwrap()
5461
}
@@ -61,10 +68,10 @@ fn successfully_retrieve_request_cookie() {
6168
let body = block_on(async move {
6269
let mut buffer = Vec::new();
6370
res.read_to_end(&mut buffer).await.unwrap();
64-
buffer
71+
String::from_utf8(buffer).unwrap()
6572
});
6673

67-
assert_eq!(&*body, &*b"RequestCookieValue");
74+
assert_eq!(&body, "RequestCookieValue and also OtherCookieValue");
6875
}
6976

7077
#[test]

0 commit comments

Comments
 (0)