Skip to content

Commit 78c8497

Browse files
committed
Code review: minor improvements
1 parent d9dbe6c commit 78c8497

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

lychee-bin/tests/cli.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,9 +2798,6 @@ The config file should contain every possible key for documentation purposes."
27982798
.arg(server.uri())
27992799
.assert()
28002800
.success();
2801-
2802-
// wiremock will fail if the expected request was not received
2803-
server.verify().await;
28042801
}
28052802

28062803
#[tokio::test]
@@ -2825,8 +2822,9 @@ The config file should contain every possible key for documentation purposes."
28252822
let user_agent = received_request
28262823
.headers
28272824
.get("user-agent")
2828-
.and_then(|v| v.to_str().ok())
2829-
.unwrap_or("");
2825+
.expect("User agent missing")
2826+
.to_str()
2827+
.unwrap();
28302828

28312829
assert!(
28322830
user_agent.starts_with("lychee/"),

lychee-lib/src/collector.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,13 @@ mod tests {
621621
use wiremock::{Mock, MockServer, ResponseTemplate};
622622

623623
let mock_server = MockServer::start().await;
624+
let uri = Uri::try_from("https://example.com").unwrap();
624625

625626
Mock::given(method("GET"))
626627
.and(path("/"))
627628
.and(header("user-agent", "test-agent/1.0"))
628629
.respond_with(
629-
ResponseTemplate::new(200)
630-
.set_body_string(r#"<a href="https://example.com">Link</a>"#),
630+
ResponseTemplate::new(200).set_body_string(format!(r#"<a href="{uri}">Link</a>"#)),
631631
)
632632
.expect(1)
633633
.mount(&mock_server)
@@ -653,8 +653,7 @@ mod tests {
653653
.collect::<std::collections::HashSet<_>>()
654654
.await;
655655

656-
assert!(links.iter().any(|u| u.url.as_str().contains("example.com")));
657-
// wiremock will panic here if the expected request was not received
656+
assert_eq!(links, HashSet::from([uri]));
658657
}
659658

660659
#[tokio::test]

lychee-lib/src/types/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl UrlContentResolver {
5151
// Fetch with body since we need to extract links from the content.
5252
let response = self.host_pool.execute_request(request, true).await?;
5353

54-
// needs_body=true above guarantees text is populated on success.
54+
// SAFETY: needs_body=true above guarantees text is populated on success.
5555
let content = response.text.unwrap_or_else(|| {
5656
unreachable!("execute_request with needs_body=true always returns text")
5757
});

0 commit comments

Comments
 (0)