Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
QpxDesign committed Jul 5, 2024
1 parent ea8a25a commit e230386
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build & Run Tests
run-name: Build & Test Project Across 10+ Test Cases 🚀
on: [push]
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Build project
run: cargo build -r --verbose

- name: Install Test Runner
run: cargo install qbtt

- name: Run Tests
id: run_tests
run: cd tests && cargo run
Binary file added src/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion src/utils/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ lazy_static! {
}

pub async fn get_text_elements_from_url(url: String, use_chrome: Option<bool>) -> Vec<String> {
let text_selector = Selector::parse("p, h1, h2, h3, h4, h5, blockquote, dd, div, dl, dt, figcaption, figure, hr, li, menu, ol, p, pre, ul, a, abbr, b, bdi, bdo, br, cite, code, data, dfn, em, i, kbd, mark, q, rp, rt, ruby, s, samp, small, span, strong, sub, sup, time, u, var, wbr, caption, col, colgroup, table, tbody, td, tfoot, th, thead, tr, noscript").unwrap();
let text_selector = Selector::parse("p, h1, h2, h3, h4, h5, blockquote, dd, div, dl, dt, figcaption, figure, hr, li, menu, ol, p, pre, ul, a, abbr, b, bdi, bdo, br, cite, code, data, dfn, em, i, kbd, mark, q, rp, rt, ruby, s, samp, small, span, strong, sub, sup, time, u, var, wbr, caption, col, colgroup, table, tbody, td, tfoot, th, thead, tr, noscript, font").unwrap();
let mut parsed_html = Html::new_document();
if use_chrome.is_some() && use_chrome.unwrap() {
parsed_html = browse_for_html_from_url(url.clone()).await;
Expand Down
59 changes: 59 additions & 0 deletions tests/test_cases.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[[test_cases]]
name = "HttpRequest/Basic"
run_type = "output"
cmd = "../target/release/webgrep https://quinnpatwardhan.com"
expect = "JavaScript"

[[test_cases]]
name = "HttpRequest/html"
run_type = "output"
cmd = "../target/release/webgrep https://trec.nist.gov/faq.html"
expect = "DARPA"

[[test_cases]]
name = "HttpRequest/Recursive1-FoundLink"
run_type = "output"
cmd = "../target/release/webgrep https://trec.nist.gov/overview.html -r 1"
expect = "Traversed http://www.nist.gov/privacy-policy"

[[test_cases]]
name = "HttpRequest/Recursive1-ExploredLink"
run_type = "output"
cmd = "../target/release/webgrep https://trec.nist.gov/overview.html -r 1"
expect = "Cookies"

[[test_cases]]
name = "HttpRequest/Recursive1-PathContains"
run_type = "checksum"
cmd = "../target/release/webgrep http://infolab.stanford.edu/pub/voy/museum.html shsadu --pathcontains people -r 1"
expect = "05a09747b2f15d953cccb061cd39c971"

[[test_cases]]
name = "HttpRequest/Recursive1-SameHost"
run_type = "output"
cmd = "../target/release/webgrep https://exhibits.stanford.edu/cs/about/timeline sdhb -r 1 --samehost"
expect = "Not Traversing policies.google.com due to samehost being true"

[[test_cases]]
name = "ChromeRequest/Basic"
run_type = "output"
cmd = "../target/release/webgrep https://quinnpatwardhan.com/aboutme -c"
expect = "New York Times"

[[test_cases]]
name = "ChromeRequest/Recursive"
run_type = "output"
cmd = "../target/release/webgrep https://quinnpatwardhan.com/aboutme -c -r 1 --samehost"
expect = "https://quinnpatwardhan.com/contact:"

[[test_cases]]
name = "PDF/NoRecursive"
run_type = "output"
cmd = "../target/release/webgrep https://quinnpatwardhan.com/Assets/Resume.pdf"
expect = "InfoSense"

[[test_cases]]
name = "Search/Basic"
run_type = "output"
cmd = "../target/release/webgrep https://quinnpatwardhan.com/aboutme Ravens -c"
expect = "die-hard"

0 comments on commit e230386

Please sign in to comment.