-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor tests folder structure
- Loading branch information
1 parent
cd043e4
commit 1070460
Showing
24 changed files
with
375 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ strum = "0.26.3" | |
strum_macros = "0.26.4" | ||
|
||
[dev-dependencies] | ||
automod = "1.0.14" | ||
stubr = "0.6.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pub mod constants { | ||
pub const TEST_DOMAIN: &str = "foo.com"; | ||
pub const TEST_BAR_SUBDOMAIN: &str = "bar.foo.com"; | ||
pub const TEST_BAZ_SUBDOMAIN: &str = "baz.foo.com"; | ||
pub const READ_ERROR: &str = "Cannot read file!"; | ||
} | ||
|
||
pub mod funcs { | ||
use super::constants::READ_ERROR; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
fn testdata_path() -> PathBuf { | ||
Path::new(env!("CARGO_MANIFEST_DIR")).join("testing/testdata") | ||
} | ||
|
||
pub fn read_testdata(path: &str) -> String { | ||
fs::read_to_string(testdata_path().join(path)).expect(READ_ERROR) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::common::{ | ||
constants::{TEST_BAR_SUBDOMAIN, TEST_BAZ_SUBDOMAIN, TEST_DOMAIN}, | ||
funcs::read_testdata, | ||
}; | ||
use subscan::extractors::html::HTMLExtractor; | ||
use subscan::interfaces::extractor::SubdomainExtractorInterface; | ||
|
||
#[tokio::test] | ||
async fn extract_without_removes() { | ||
let html = read_testdata("html/subdomains.html"); | ||
|
||
let selector = String::from("article > div > a > span:first-child"); | ||
let extractor = HTMLExtractor::new(selector, vec![]); | ||
let result = extractor.extract(html, TEST_DOMAIN.to_string()).await; | ||
|
||
assert_eq!(result, [TEST_BAR_SUBDOMAIN.to_string()].into()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn extract_with_removes() { | ||
let html = read_testdata("html/subdomains-with-removes.html"); | ||
|
||
let selector = String::from("article > div > a > span"); | ||
let extractor = HTMLExtractor::new(selector, vec!["<br>".to_string()]); | ||
let result = extractor.extract(html, TEST_DOMAIN.to_string()).await; | ||
|
||
let expected = [ | ||
TEST_BAR_SUBDOMAIN.to_string(), | ||
TEST_BAZ_SUBDOMAIN.to_string(), | ||
]; | ||
|
||
assert_eq!(result, expected.into()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
automod::dir!("tests/extractors"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::common::constants::{TEST_BAR_SUBDOMAIN, TEST_BAZ_SUBDOMAIN, TEST_DOMAIN}; | ||
use subscan::extractors::regex::RegexExtractor; | ||
use subscan::interfaces::extractor::SubdomainExtractorInterface; | ||
|
||
#[tokio::test] | ||
async fn extract_one_test() { | ||
let extractor = RegexExtractor::default(); | ||
|
||
let matches = String::from(TEST_BAR_SUBDOMAIN); | ||
let no_match = String::from("foobarbaz"); | ||
|
||
assert!(extractor | ||
.extract_one(matches, TEST_DOMAIN.to_string()) | ||
.is_some()); | ||
assert!(extractor | ||
.extract_one(no_match, TEST_DOMAIN.to_string()) | ||
.is_none()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn extract_test() { | ||
let content = String::from("bar.foo.com\nbaz.foo.com"); | ||
|
||
let extractor = RegexExtractor::default(); | ||
let result = extractor.extract(content, TEST_DOMAIN.to_string()).await; | ||
|
||
let expected = [ | ||
TEST_BAR_SUBDOMAIN.to_string(), | ||
TEST_BAZ_SUBDOMAIN.to_string(), | ||
]; | ||
|
||
assert_eq!(result, expected.into()); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::common::constants::{TEST_BAR_SUBDOMAIN, TEST_DOMAIN}; | ||
use reqwest::Url; | ||
use subscan::{interfaces::module::SubscanModuleInterface, modules::engines::bing}; | ||
|
||
#[tokio::test] | ||
#[stubr::mock("module/engines/bing.json")] | ||
async fn bing_run_test() { | ||
let mut bing = bing::Bing::new(); | ||
|
||
bing.url = Url::parse(stubr.path("/search").as_str()).unwrap(); | ||
|
||
let result = bing.run(TEST_DOMAIN.to_string()).await; | ||
|
||
assert_eq!(bing.name().await, "Bing"); | ||
assert_eq!(result, [TEST_BAR_SUBDOMAIN.to_string()].into()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::common::constants::{TEST_BAR_SUBDOMAIN, TEST_DOMAIN}; | ||
use reqwest::Url; | ||
use subscan::{ | ||
cache::requesters, enums::RequesterType, interfaces::module::SubscanModuleInterface, | ||
modules::engines::duckduckgo, | ||
}; | ||
|
||
#[tokio::test] | ||
#[stubr::mock("module/engines/duckduckgo.json")] | ||
async fn duckduckgo_run_test() { | ||
let mut duckduckgo = duckduckgo::DuckDuckGo::new(); | ||
|
||
duckduckgo.requester = requesters::get_by_type(&RequesterType::HTTPClient); | ||
duckduckgo.url = Url::parse(stubr.uri().as_str()).unwrap(); | ||
|
||
let result = duckduckgo.run(TEST_DOMAIN.to_string()).await; | ||
|
||
assert_eq!(duckduckgo.name().await, "DuckDuckGo"); | ||
assert_eq!(result, [TEST_BAR_SUBDOMAIN.to_string()].into()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::common::constants::{TEST_BAR_SUBDOMAIN, TEST_DOMAIN}; | ||
use reqwest::Url; | ||
use subscan::{interfaces::module::SubscanModuleInterface, modules::engines::google}; | ||
|
||
#[tokio::test] | ||
#[stubr::mock("module/engines/google.json")] | ||
async fn foo_test() { | ||
let mut google = google::Google::new(); | ||
|
||
google.url = Url::parse(stubr.path("/search").as_str()).unwrap(); | ||
|
||
let result = google.run(TEST_DOMAIN.to_string()).await; | ||
|
||
assert_eq!(google.name().await, "Google"); | ||
assert_eq!(result, [TEST_BAR_SUBDOMAIN.to_string()].into()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
automod::dir!("tests/modules/engines"); |
Oops, something went wrong.