NewPodcast: Remove the boilerplate on the unit tests.

This commit is contained in:
Jordan Petridis 2018-01-21 08:57:50 +02:00
parent 1625f773c2
commit 410657c98b
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -160,19 +160,16 @@ mod tests {
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
#[test] // Pre-built expected NewPodcast structs.
fn test_new_podcast_intercepted() { lazy_static!{
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap(); static ref EXPECTED_INTERCEPT: NewPodcast = {
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let descr = "The people behind The Intercepts fearless reporting and incisive \ let descr = "The people behind The Intercepts fearless reporting and incisive \
commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and othersdiscuss \ commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and othersdiscuss \
the crucial issues of our time: national security, civil liberties, foreign \ the crucial issues of our time: national security, civil liberties, foreign \
policy, and criminal justice. Plus interviews with artists, thinkers, and \ policy, and criminal justice. Plus interviews with artists, thinkers, and \
newsmakers who challenge our preconceptions about the world we live in."; newsmakers who challenge our preconceptions about the world we live in.";
let pd = NewPodcast::new(&channel, 0); NewPodcastBuilder::default()
let expected = NewPodcastBuilder::default()
.title("Intercepted with Jeremy Scahill") .title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts") .link("https://theintercept.com/podcasts")
.description(descr) .description(descr)
@ -182,22 +179,15 @@ mod tests {
2FIntercepted_COVER%2B_281_29.png") 2FIntercepted_COVER%2B_281_29.png")
)) ))
.build() .build()
.unwrap(); .unwrap()
};
assert_eq!(pd, expected);
}
#[test]
fn test_new_podcast_lup() {
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
static ref EXPECTED_LUP: NewPodcast = {
let descr = "An open show powered by community LINUX Unplugged takes the best attributes \ let descr = "An open show powered by community LINUX Unplugged takes the best attributes \
of open collaboration and focuses them into a weekly lifestyle show about \ of open collaboration and focuses them into a weekly lifestyle show about \
Linux."; Linux.";
let pd = NewPodcast::new(&channel, 0);
let expected = NewPodcastBuilder::default() NewPodcastBuilder::default()
.title("LINUX Unplugged Podcast") .title("LINUX Unplugged Podcast")
.link("http://www.jupiterbroadcasting.com/") .link("http://www.jupiterbroadcasting.com/")
.description(descr) .description(descr)
@ -205,16 +195,10 @@ mod tests {
"http://www.jupiterbroadcasting.com/images/LASUN-Badge1400.jpg", "http://www.jupiterbroadcasting.com/images/LASUN-Badge1400.jpg",
))) )))
.build() .build()
.unwrap(); .unwrap()
};
assert_eq!(pd, expected);
}
#[test]
fn test_new_podcast_thetipoff() {
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
static ref EXPECTED_TIPOFF: NewPodcast = {
let desc = "Welcome to The Tip Off- the podcast where we take you behind the scenes of \ let desc = "Welcome to The Tip Off- the podcast where we take you behind the scenes of \
some of the best investigative journalism from recent years. Each episode \ some of the best investigative journalism from recent years. Each episode \
well be digging into an investigative scoop- hearing from the journalists \ well be digging into an investigative scoop- hearing from the journalists \
@ -224,9 +208,8 @@ mod tests {
much more. So if youre curious about the fun, complicated detective work \ much more. So if youre curious about the fun, complicated detective work \
that goes into doing great investigative journalism- then this is the podcast \ that goes into doing great investigative journalism- then this is the podcast \
for you."; for you.";
let pd = NewPodcast::new(&channel, 0);
let expected = NewPodcastBuilder::default() NewPodcastBuilder::default()
.title("The Tip Off") .title("The Tip Off")
.link("http://www.acast.com/thetipoff") .link("http://www.acast.com/thetipoff")
.description(desc) .description(desc)
@ -235,16 +218,11 @@ mod tests {
com%2Favatars-000317856075-a2coqz-original.jpg", com%2Favatars-000317856075-a2coqz-original.jpg",
))) )))
.build() .build()
.unwrap(); .unwrap()
assert_eq!(pd, expected); };
}
#[test]
fn test_new_podcast_steal_the_stars() {
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
static ref EXPECTED_STARS: NewPodcast = {
let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars is \ let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars is \
a gripping noir science fiction thriller in 14 episodes: Forbidden love, a \ a gripping noir science fiction thriller in 14 episodes: Forbidden love, a \
crashed UFO, an alien body, and an impossible heist unlike any ever \ crashed UFO, an alien body, and an impossible heist unlike any ever \
@ -253,30 +231,22 @@ mod tests {
let img = "https://dfkfj8j276wwv.cloudfront.net/images/2c/5f/a0/1a/2c5fa01a-ae78-4a8c-\ let img = "https://dfkfj8j276wwv.cloudfront.net/images/2c/5f/a0/1a/2c5fa01a-ae78-4a8c-\
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\ b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg"; 923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
let pd = NewPodcast::new(&channel, 0);
let expected = NewPodcastBuilder::default() NewPodcastBuilder::default()
.title("Steal the Stars") .title("Steal the Stars")
.link("http://tor-labs.com/") .link("http://tor-labs.com/")
.description(descr) .description(descr)
.image_uri(Some(String::from(img))) .image_uri(Some(String::from(img)))
.build() .build()
.unwrap(); .unwrap()
};
assert_eq!(pd, expected);
}
#[test]
fn test_new_podcast_greater_than_code() {
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
static ref EXPECTED_CODE: NewPodcast = {
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, David \ let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, David \
Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam Livingston-Gray. \ Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam Livingston-Gray. \
Brought to you by @therubyrep."; Brought to you by @therubyrep.";
let pd = NewPodcast::new(&channel, 0);
let expected = NewPodcastBuilder::default() NewPodcastBuilder::default()
.title("Greater Than Code") .title("Greater Than Code")
.link("https://www.greaterthancode.com/") .link("https://www.greaterthancode.com/")
.description(descr) .description(descr)
@ -284,9 +254,53 @@ mod tests {
"http://www.greaterthancode.com/wp-content/uploads/2016/10/code1400-4.jpg", "http://www.greaterthancode.com/wp-content/uploads/2016/10/code1400-4.jpg",
))) )))
.build() .build()
.unwrap(); .unwrap()
};
}
assert_eq!(pd, expected); #[test]
fn test_new_podcast_intercepted() {
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 0);
assert_eq!(&*EXPECTED_INTERCEPT, &pd);
}
#[test]
fn test_new_podcast_lup() {
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 0);
assert_eq!(&*EXPECTED_LUP, &pd);
}
#[test]
fn test_new_podcast_thetipoff() {
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 0);
assert_eq!(&*EXPECTED_TIPOFF, &pd);
}
#[test]
fn test_new_podcast_steal_the_stars() {
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 0);
assert_eq!(&*EXPECTED_STARS, &pd);
}
#[test]
fn test_new_podcast_greater_than_code() {
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 0);
assert_eq!(&*EXPECTED_CODE, &pd);
} }
#[test] #[test]
@ -300,26 +314,8 @@ mod tests {
npd.insert().unwrap(); npd.insert().unwrap();
let pd = dbqueries::get_podcast_from_source_id(0).unwrap(); let pd = dbqueries::get_podcast_from_source_id(0).unwrap();
let descr = "The people behind The Intercepts fearless reporting and incisive \
commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and othersdiscuss \
the crucial issues of our time: national security, civil liberties, foreign \
policy, and criminal justice. Plus interviews with artists, thinkers, and \
newsmakers who challenge our preconceptions about the world we live in.";
let expected = NewPodcastBuilder::default()
.title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts")
.description(descr)
.image_uri(Some(String::from(
"http://static.megaphone.fm/podcasts/d5735a50-d904-11e6-8532-73c7de466ea6/image/\
uploads_2F1484252190700-qhn5krasklbce3dh-a797539282700ea0298a3a26f7e49b0b_\
2FIntercepted_COVER%2B_281_29.png")
))
.build()
.unwrap();
assert_eq!(npd, pd); assert_eq!(npd, pd);
assert_eq!(&expected, &pd); assert_eq!(&*EXPECTED_INTERCEPT, &pd);
assert_eq!(&expected, &npd); assert_eq!(&*EXPECTED_INTERCEPT, &npd);
} }
} }