Skip to content

Commit 21b25b4

Browse files
committed
Add test when url is invalid and panic
1 parent 2d19755 commit 21b25b4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tests/test_reqwest_async.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use robotparser::service::RobotsTxtService;
33
use reqwest::Client;
44
use url::Url;
55
use tokio::runtime::Runtime;
6+
use url::{Host, Origin};
67

78
#[test]
89
fn test_reqwest_async() {
@@ -13,4 +14,15 @@ fn test_reqwest_async() {
1314
let robots_txt = robots_txt_response.unwrap().get_result();
1415
let fetch_url = Url::parse("http://www.python.org/robots.txt").unwrap();
1516
assert!(robots_txt.can_fetch("*", &fetch_url));
16-
}
17+
let fetch_url = Url::parse("http://www.python.org/webstats/").unwrap();
18+
assert!(!robots_txt.can_fetch("*", &fetch_url));
19+
}
20+
21+
#[test]
22+
#[should_panic]
23+
fn test_reqwest_blocking_panic_url() {
24+
let client = Client::new();
25+
let host = Host::Domain("python.org::".into());
26+
let origin = Origin::Tuple("https".into(), host, 80);
27+
client.fetch_robots_txt(origin);
28+
}

tests/test_reqwest_blocking.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use robotparser::http::RobotsTxtClient;
22
use robotparser::service::RobotsTxtService;
33
use reqwest::blocking::Client;
44
use url::Url;
5+
use url::{Host, Origin};
56

67
#[test]
78
fn test_reqwest_blocking() {
@@ -10,4 +11,15 @@ fn test_reqwest_blocking() {
1011
let robots_txt = client.fetch_robots_txt(robots_txt_url.origin()).unwrap().get_result();
1112
let fetch_url = Url::parse("http://www.python.org/robots.txt").unwrap();
1213
assert!(robots_txt.can_fetch("*", &fetch_url));
14+
let fetch_url = Url::parse("http://www.python.org/webstats/").unwrap();
15+
assert!(!robots_txt.can_fetch("*", &fetch_url));
16+
}
17+
18+
#[test]
19+
#[should_panic]
20+
fn test_reqwest_blocking_panic_url() {
21+
let client = Client::new();
22+
let host = Host::Domain("python.org::".into());
23+
let origin = Origin::Tuple("https".into(), host, 80);
24+
client.fetch_robots_txt(origin).unwrap().get_result();
1325
}

0 commit comments

Comments
 (0)