Skip to content

Commit

Permalink
revert conn-id test changes, update specific data
Browse files Browse the repository at this point in the history
the issue wasn't actually some sort of os-based or multithreading issue, but that fastrand changed the random generation behavior on a post 1.0 semver-minor release, so CI updated to a version I was not using locally. smol-rs/fastrand#20
  • Loading branch information
jbr committed Jul 20, 2021
1 parent 2a3903e commit 93c8127
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
19 changes: 12 additions & 7 deletions conn-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ impl ConnId {
```
# use trillium_testing::prelude::*;
# use trillium_conn_id::ConnId;
fastrand::seed(1000); // for testing, so our id is predictable
let app = (ConnId::new(), "ok");
assert_eq!(get("/").on(&app).headers_mut()["x-request-id"].as_str().len(), 10);
assert_ok!(
get("/").on(&app),
"ok",
"x-request-id" => "U14baHj9ho"
);
assert_headers!(
get("/")
Expand Down Expand Up @@ -128,17 +132,18 @@ impl ConnId {
```
# use trillium_testing::prelude::*;
# use trillium_conn_id::{ConnId, ConnIdExt};
# use trillium_conn_id::ConnId;
fastrand::seed(1000); // for testing, so our id is predictable
let app = (
ConnId::new().with_response_header(Some("x-custom-header")),
"ok"
);
let mut conn = get("/").on(&app);
let id = String::from(conn.id());
assert_headers!(&mut conn, "x-custom-header" => &*id);
assert_headers!(
get("/").on(&app),
"x-custom-header" => "U14baHj9ho"
);
```
*/
pub fn with_response_header(mut self, response_header: Option<&'static str>) -> Self {
Expand Down
17 changes: 9 additions & 8 deletions conn-id/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use uuid::Uuid;

#[test]
fn test_defaults() {
fastrand::seed(1000);
let app = (ConnId::new(), "ok");
let mut conn = get("/").on(&app);
let id = String::from(conn.id());
assert_eq!(id, conn.headers_mut()["x-request-id"].as_str());
assert_eq!(conn.id().len(), 10);

assert_ok!(get("/").on(&app), "ok", "x-request-id" => "U14baHj9ho");
assert_ok!(get("/").on(&app), "ok", "x-request-id" => "AawiNNFjGW");
assert_ok!(
get("/").with_request_header(("x-request-id", "inbound-id")).on(&app),
"ok",
"x-request-id" => "inbound-id"
);

let conn = get("/").on(&app);
assert_eq!(log_formatter::conn_id(&conn, true), conn.id());
assert_eq!(conn.id(), "iHxXDjwzU5");
assert_eq!(log_formatter::conn_id(&conn, true), "iHxXDjwzU5");

let conn = TestConn::build("get", "/", ());
assert_eq!(log_formatter::conn_id(&conn, true), "-");
Expand Down Expand Up @@ -48,21 +48,22 @@ fn test_settings() {

#[test]
fn test_no_headers() {
fastrand::seed(1000);

let app = (
ConnId::new()
.with_id_generator(|| "test".into())
.with_request_header(None)
.with_response_header(None),
"ok",
);

let mut conn = get("/").on(&app);
assert!(conn.headers_mut().get("x-request-id").is_none());
assert_eq!(conn.id(), "test");
assert_eq!(conn.id(), "U14baHj9ho");

let mut conn = get("/")
.with_request_header(("x-request-id", "ignored"))
.on(&app);
assert_eq!(conn.id(), "test");
assert_eq!(conn.id(), "AawiNNFjGW");
assert!(conn.headers_mut().get("x-request-id").is_none());
}

0 comments on commit 93c8127

Please sign in to comment.