test_complete_index cleanup.

This commit is contained in:
Jordan Petridis 2017-10-02 11:48:58 +03:00
parent 10834b75dc
commit 42cef658fc
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -272,40 +272,34 @@ mod tests {
// complete_index runs in parallel so it requires a mutex as argument. // complete_index runs in parallel so it requires a mutex as argument.
let m = Arc::new(Mutex::new(db)); let m = Arc::new(Mutex::new(db));
// map the filenames to their feeds url. // vec of (path, url) tuples.
let mut urls = HashMap::new(); let urls = vec![
urls.insert( (
"Intercepted.xml", "tests/feeds/Intercepted.xml",
"https://feeds.feedburner.com/InterceptedWithJeremyScahill", "https://feeds.feedburner.com/InterceptedWithJeremyScahill",
); ),
urls.insert( (
"LinuxUnplugged.xml", "tests/feeds/LinuxUnplugged.xml",
"http://feeds.feedburner.com/linuxunplugged", "http://feeds.feedburner.com/linuxunplugged",
); ),
urls.insert( (
"TheBreakthrough.xml", "tests/feeds/TheBreakthrough.xml",
"http://feeds.feedburner.com/propublica/podcast", "http://feeds.feedburner.com/propublica/podcast",
); ),
urls.insert( (
"R4Explanation.xml", "tests/feeds/R4Explanation.xml",
"https://request-for-explanation.github.io/podcast/rss.xml", "https://request-for-explanation.github.io/podcast/rss.xml",
); ),
];
let feeds_path = fs::read_dir("./tests/feeds/").unwrap();
// feeds_path.for_each(|x| println!("{}", x.unwrap().path().display()));
feeds_path.for_each(|x| {
let x = x.unwrap();
let name = x.file_name();
let url = urls.get(name.to_str().unwrap());
urls.iter().for_each(|&(path, url)| {
let tempdb = m.lock().unwrap(); let tempdb = m.lock().unwrap();
// Create and insert a Source into db // Create and insert a Source into db
let s = insert_return_source(&tempdb, url.unwrap()).unwrap(); let s = insert_return_source(&tempdb, url).unwrap();
drop(tempdb); drop(tempdb);
// open the xml file // open the xml file
let feed = fs::File::open(x.path()).unwrap(); let feed = fs::File::open(path).unwrap();
// parse it into a channel // parse it into a channel
let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap(); let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap();