Skip to content

Commit a54f81d

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

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

lychee-bin/src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,6 @@ async fn run(opts: &LycheeOptions) -> Result<i32> {
340340
)
341341
})?;
342342

343-
// Build the lychee client first so we can share its HostPool with the
344-
// collector. This ensures that fetching remote input documents uses the
345-
// same user-agent, TLS settings, cookies, per-host rate limits and custom
346-
// headers as regular link checks.
347343
let client = client::create(&opts.config, cookie_jar.as_deref())?;
348344

349345
let mut collector = Collector::new(opts.config.root_dir.clone(), base.unwrap_or_default())?

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: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ impl Collector {
157157
/// fetches share the same user-agent, TLS settings, cookies, per-host
158158
/// rate limits and headers as regular link checks:
159159
///
160-
/// ```ignore
161-
/// let lychee_client = ClientBuilder::builder().client()?;
162-
/// let collector = Collector::new(…)?
163-
/// .host_pool(lychee_client.host_pool());
160+
/// ```
161+
/// # use lychee_lib::{BaseInfo, ClientBuilder, Collector, ErrorKind};
162+
/// let client = ClientBuilder::builder().build().client()?;
163+
/// let collector = Collector::new(None, BaseInfo::none())?
164+
/// .host_pool(client.host_pool());
165+
/// # Ok::<(), ErrorKind>(())
164166
/// ```
165167
#[must_use]
166168
pub fn host_pool(mut self, host_pool: Arc<HostPool>) -> Self {
@@ -621,13 +623,13 @@ mod tests {
621623
use wiremock::{Mock, MockServer, ResponseTemplate};
622624

623625
let mock_server = MockServer::start().await;
626+
let uri = Uri::try_from("https://example.com").unwrap();
624627

625628
Mock::given(method("GET"))
626629
.and(path("/"))
627630
.and(header("user-agent", "test-agent/1.0"))
628631
.respond_with(
629-
ResponseTemplate::new(200)
630-
.set_body_string(r#"<a href="https://example.com">Link</a>"#),
632+
ResponseTemplate::new(200).set_body_string(format!(r#"<a href="{uri}">Link</a>"#)),
631633
)
632634
.expect(1)
633635
.mount(&mock_server)
@@ -653,8 +655,7 @@ mod tests {
653655
.collect::<std::collections::HashSet<_>>()
654656
.await;
655657

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
658+
assert_eq!(links, HashSet::from([uri]));
658659
}
659660

660661
#[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)