Fix exclude mail, add tests

This commit is contained in:
Matthias Endler 2021-03-29 23:28:17 +02:00
parent bcb3933b22
commit 2b044a6f5b
5 changed files with 50 additions and 1 deletions

6
fixtures/TEST_EMAIL.md Normal file
View file

@ -0,0 +1,6 @@
https://endler.dev
test@example.org
foo@bar.dev
https://example.org
octocat+github@github.com
mailto:test2@example.org

View file

@ -107,6 +107,7 @@ async fn run(cfg: &Config, inputs: Vec<Input>) -> Result<i32> {
.exclude_private_ips(cfg.exclude_private)
.exclude_link_local_ips(cfg.exclude_link_local)
.exclude_loopback_ips(cfg.exclude_loopback)
.exclude_mail(cfg.exclude_mail)
.max_redirects(cfg.max_redirects)
.user_agent(cfg.user_agent.clone())
.allow_insecure(cfg.insecure)

View file

@ -95,7 +95,7 @@ impl ClientBuilder {
private_ips: enable_exclude(self.exclude_private_ips.unwrap_or_default()),
link_local_ips: enable_exclude(self.exclude_link_local_ips.unwrap_or_default()),
loopback_ips: enable_exclude(self.exclude_loopback_ips.unwrap_or_default()),
mail: enable_exclude(self.exclude_mail.unwrap_or_default()),
mail: self.exclude_mail.unwrap_or_default(),
}
}

View file

@ -188,6 +188,31 @@ mod test {
assert_eq!(filter.excluded(&request("https://example.org")), true);
}
#[test]
fn test_exclude_mail() {
let excludes = Excludes {
mail: true,
..Default::default()
};
let filter = Filter::new(None, Some(excludes), None);
assert_eq!(
filter.excluded(&Request::new(
Uri::Mail("mail@example.org".to_string()),
Input::Stdin,
)),
true
);
assert_eq!(
filter.excluded(&Request::new(
Uri::Mail("foo@bar.dev".to_string()),
Input::Stdin,
)),
true
);
assert_eq!(filter.excluded(&request("http://bar.dev")), false);
}
#[test]
fn test_exclude_regex() {
let excludes = Excludes {

View file

@ -36,6 +36,23 @@ mod cli {
.stdout(contains("Errors...........0"));
}
#[test]
fn test_exclude_email() {
let mut cmd = main_command();
let test_path = fixtures_path().join("TEST_EMAIL.md");
// assert that the command runs OK, and that it excluded all the links
cmd.arg("--exclude-mail")
.arg(test_path)
.assert()
.success()
.stdout(contains("Total............6"))
.stdout(contains("Excluded.........4"))
.stdout(contains("Successful.......2"))
.stdout(contains("Errors...........0"));
}
/// Test that a GitHub link can be checked without specifying the token.
#[test]
fn test_check_github_no_token() {