mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-17 05:00:26 +00:00
* Make GITHUB_TOKEN optional This also makes the token possible to pass in from CLI args. * Add missing test fixture file * Normalize exit codes and GitHub checking behavior The exit code is now defined as 1 for unexpected or config errors, and 2 for link check failures. GitHub checking behavior has been tweaked to generate errors if a GitHub-specific check cannot be performed because of a missing token. * Remove short flag for github token
99 lines
3.1 KiB
Rust
99 lines
3.1 KiB
Rust
#[cfg(test)]
|
|
mod cli {
|
|
use assert_cmd::Command;
|
|
use predicates::str::contains;
|
|
use std::path::Path;
|
|
|
|
#[test]
|
|
fn test_exclude_all_private() {
|
|
// this gets the "main" binary name (e.g. `lychee`)
|
|
let mut cmd =
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name");
|
|
|
|
let test_all_private_path = Path::new(module_path!())
|
|
.parent()
|
|
.unwrap()
|
|
.join("fixtures")
|
|
.join("TEST_ALL_PRIVATE.md");
|
|
|
|
// assert that the command runs OK, and that it excluded all the links
|
|
cmd.arg("--exclude-all-private")
|
|
.arg("--verbose")
|
|
.arg(test_all_private_path)
|
|
.assert()
|
|
.success()
|
|
.stdout(contains("Found: 7"))
|
|
.stdout(contains("Excluded: 7"))
|
|
.stdout(contains("Successful: 0"))
|
|
.stdout(contains("Errors: 0"));
|
|
}
|
|
|
|
/// Test that a GitHub link can be checked without specifying the token.
|
|
#[test]
|
|
fn test_check_github_no_token() {
|
|
let mut cmd =
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name");
|
|
|
|
let test_github_path = Path::new(module_path!())
|
|
.parent()
|
|
.unwrap()
|
|
.join("fixtures")
|
|
.join("TEST_GITHUB.md");
|
|
|
|
cmd.arg("--verbose")
|
|
.arg(test_github_path)
|
|
.assert()
|
|
.success()
|
|
.stdout(contains("Found: 1"))
|
|
.stdout(contains("Excluded: 0"))
|
|
.stdout(contains("Successful: 1"))
|
|
.stdout(contains("Errors: 0"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_failure_invalid_method() {
|
|
let mut cmd =
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name");
|
|
|
|
cmd.arg("--method=invalid-method")
|
|
.assert()
|
|
.failure()
|
|
.code(1)
|
|
.stderr(contains(
|
|
"Error: Only `get` and `head` allowed, got invalid-method",
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn test_failure_404_link() {
|
|
let mut cmd =
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name");
|
|
|
|
let test_404_path = Path::new(module_path!())
|
|
.parent()
|
|
.unwrap()
|
|
.join("fixtures")
|
|
.join("TEST_404.md");
|
|
|
|
cmd.arg(test_404_path).assert().failure().code(2);
|
|
}
|
|
|
|
#[test]
|
|
fn test_failure_github_404_no_token() {
|
|
let mut cmd =
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name");
|
|
|
|
let test_github_404_path = Path::new(module_path!())
|
|
.parent()
|
|
.unwrap()
|
|
.join("fixtures")
|
|
.join("TEST_GITHUB_404.md");
|
|
|
|
cmd.arg(test_github_404_path)
|
|
.assert()
|
|
.failure()
|
|
.code(2)
|
|
.stdout(contains("https://github.com/mre/idiomatic-rust-doesnt-exist-man \
|
|
(GitHub token not specified. To check GitHub links reliably, use `--github-token` flag / `GITHUB_TOKEN` env var.)"));
|
|
}
|
|
}
|