mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-31 03:40:24 +00:00
Add/change file link tests
This commit is contained in:
parent
ee70e13bf7
commit
daa5be4c3a
3 changed files with 35 additions and 14 deletions
|
|
@ -130,15 +130,22 @@ mod cli {
|
|||
|
||||
/// Test unsupported URI schemes
|
||||
#[test]
|
||||
fn test_unsupported_uri_schemes() -> Result<()> {
|
||||
test_json_output!(
|
||||
"TEST_SCHEMES.txt",
|
||||
MockResponseStats {
|
||||
total: 1,
|
||||
successful: 1,
|
||||
..MockResponseStats::default()
|
||||
}
|
||||
)
|
||||
fn test_unsupported_uri_schemes() {
|
||||
let mut cmd = main_command();
|
||||
let test_schemes_path = fixtures_path().join("TEST_SCHEMES.txt");
|
||||
|
||||
// Exclude file link because it doesn't exist on the filesystem.
|
||||
// (File URIs are absolute paths, which we don't have.)
|
||||
// Nevertheless, the `file` scheme should be recognized.
|
||||
cmd.arg(test_schemes_path)
|
||||
.arg("--exclude")
|
||||
.arg("file://")
|
||||
.env_clear()
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(contains("Total............2"))
|
||||
.stdout(contains("Successful.......1"))
|
||||
.stdout(contains("Excluded.........1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -364,7 +371,7 @@ mod cli {
|
|||
.assert()
|
||||
.success();
|
||||
|
||||
let expected = r#"{"total":10,"successful":10,"failures":0,"timeouts":0,"redirects":0,"excludes":0,"errors":0,"fail_map":{}}"#;
|
||||
let expected = r#"{"total":11,"successful":11,"failures":0,"timeouts":0,"redirects":0,"excludes":0,"errors":0,"fail_map":{}}"#;
|
||||
let output = fs::read_to_string(&outfile)?;
|
||||
assert_eq!(output.split_whitespace().collect::<String>(), expected);
|
||||
fs::remove_file(outfile)?;
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ mod cli {
|
|||
writeln!(index, r#"<a href="./foo.html">Foo</a>"#)?;
|
||||
|
||||
let foo_path = dir.path().join("foo.html");
|
||||
let mut foo = File::create(&foo_path)?;
|
||||
writeln!(foo, r#"<a href="https://example.org">example</a>"#)?;
|
||||
File::create(&foo_path)?;
|
||||
|
||||
let mut cmd = main_command();
|
||||
cmd.arg(index_path)
|
||||
|
|
@ -30,7 +29,7 @@ mod cli {
|
|||
.assert()
|
||||
.success()
|
||||
.stdout(contains("Total............1"))
|
||||
.stdout(contains("example.org"));
|
||||
.stdout(contains("foo.html"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,10 +287,14 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{
|
||||
fs::File,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use http::{header::HeaderMap, StatusCode};
|
||||
use reqwest::header;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use super::ClientBuilder;
|
||||
use crate::{mock_server, test_utils::get_mock_client_response};
|
||||
|
|
@ -375,6 +379,17 @@ mod test {
|
|||
assert!(res.status().is_success());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_file() {
|
||||
let dir = tempdir().unwrap();
|
||||
let file = dir.path().join("temp");
|
||||
File::create(file).unwrap();
|
||||
let uri = format!("file://{}", dir.path().join("temp").to_str().unwrap());
|
||||
|
||||
let res = get_mock_client_response(uri).await;
|
||||
assert!(res.status().is_success());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_custom_headers() {
|
||||
// See https://github.com/rust-lang/crates.io/issues/788
|
||||
|
|
|
|||
Loading…
Reference in a new issue