Skip to content

Commit f71bf32

Browse files
KixironJoshua Nelson
authored and
Joshua Nelson
committed
Test all internal homepage links
1 parent 8f36bf4 commit f71bf32

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/web/releases.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ mod tests {
689689
use chrono::TimeZone;
690690
use failure::Error;
691691
use kuchiki::traits::TendrilSink;
692+
use std::collections::HashSet;
692693

693694
#[test]
694695
fn database_search() {
@@ -1170,4 +1171,47 @@ mod tests {
11701171
assert_success("/releases/frankenstein", web)
11711172
})
11721173
}
1174+
1175+
#[test]
1176+
fn home_page_links() {
1177+
wrapper(|env| {
1178+
let web = env.frontend();
1179+
env.fake_release()
1180+
.name("some_random_crate")
1181+
.author("frankenstein <[email protected]>")
1182+
.create()?;
1183+
1184+
let mut urls = vec![];
1185+
let mut seen = HashSet::new();
1186+
seen.insert("".to_owned());
1187+
1188+
let resp = web.get("").send()?;
1189+
assert!(resp.status().is_success());
1190+
1191+
let html = kuchiki::parse_html().one(resp.text()?);
1192+
for link in html.select("a").unwrap() {
1193+
let link = link.as_node().as_element().unwrap();
1194+
1195+
urls.push(link.attributes.borrow().get("href").unwrap().to_owned());
1196+
}
1197+
1198+
while let Some(url) = urls.pop() {
1199+
// Skip urls we've already checked
1200+
if !seen.insert(url.clone()) {
1201+
continue;
1202+
}
1203+
1204+
let resp = if url.starts_with("http://") || url.starts_with("https://") {
1205+
// Skip external links
1206+
continue;
1207+
} else {
1208+
web.get(&url).send()?
1209+
};
1210+
let status = resp.status();
1211+
assert!(status.is_success(), "failed to GET {}: {}", url, status);
1212+
}
1213+
1214+
Ok(())
1215+
});
1216+
}
11731217
}

0 commit comments

Comments
 (0)