mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-23 12:55:50 +00:00
Make suggestion test more robust (#1229)
This commit is contained in:
parent
5c95086f44
commit
006ee6d3be
1 changed files with 26 additions and 10 deletions
|
|
@ -14,6 +14,7 @@ mod cli {
|
||||||
use lychee_lib::{InputSource, ResponseBody};
|
use lychee_lib::{InputSource, ResponseBody};
|
||||||
use predicates::str::{contains, is_empty};
|
use predicates::str::{contains, is_empty};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
use regex::Regex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
@ -1229,18 +1230,33 @@ mod cli {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_suggests_url_alternatives() -> Result<()> {
|
fn test_suggests_url_alternatives() -> Result<()> {
|
||||||
let mut cmd = main_command();
|
for _ in 0..3 {
|
||||||
let input = fixtures_path().join("INTERNET_ARCHIVE.md");
|
// This can be flaky. Try up to 3 times
|
||||||
|
let mut cmd = main_command();
|
||||||
|
let input = fixtures_path().join("INTERNET_ARCHIVE.md");
|
||||||
|
|
||||||
cmd.arg("--suggest")
|
cmd.arg("--no-progress").arg("--suggest").arg(input);
|
||||||
.arg(input)
|
|
||||||
.assert()
|
|
||||||
.failure()
|
|
||||||
.code(2)
|
|
||||||
.stdout(contains("Suggestions"))
|
|
||||||
.stdout(contains("http://web.archive.org/web/"));
|
|
||||||
|
|
||||||
Ok(())
|
// Run he command and check if the output contains the expected
|
||||||
|
// suggestions
|
||||||
|
let assert = cmd.assert();
|
||||||
|
let output = assert.get_output();
|
||||||
|
|
||||||
|
// We're looking for a suggestion that
|
||||||
|
// - starts with http://web.archive.org/web/
|
||||||
|
// - ends with google.com/jobs.html
|
||||||
|
let re = Regex::new(r"http://web\.archive\.org/web/.*google\.com/jobs\.html").unwrap();
|
||||||
|
if re.is_match(&String::from_utf8_lossy(&output.stdout)) {
|
||||||
|
// Test passed
|
||||||
|
return Ok(());
|
||||||
|
} else {
|
||||||
|
// Wait for a second before retrying
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we reached here, it means the test did not pass after multiple attempts
|
||||||
|
Err("Did not get the expected command output after multiple attempts.".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue