Use insta for testing.

This commit is contained in:
2019-02-06 09:24:42 +01:00
parent 5a1d428c22
commit 8b1cc276d6
10 changed files with 714 additions and 702 deletions

View File

@@ -37,7 +37,7 @@ impl Probe for KonsumentInfo {
format!("http://konsumentinfo.se/telefonnummer/sverige/{}", number)
}
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
let body = if let Some(cache) = ctx.cache_get("konsument_info", &number) {
String::from_utf8(cache.data).unwrap()
} else {
@@ -49,21 +49,13 @@ impl Probe for KonsumentInfo {
body
};
match from_html(&body) {
Ok(entry) => {
println!("konsumentinfo.se:");
print!("{}", entry);
Ok(())
}
Err(_) => Err(()),
}
from_html(&body)
}
}
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use insta::assert_yaml_snapshot_matches;
use super::*;
@@ -71,90 +63,52 @@ mod tests {
fn test_0104754350() {
let document = include_str!("../../fixtures/konsumentinfo/0104754350.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
}
#[test]
fn test_0313908905() {
let document = include_str!("../../fixtures/konsumentinfo/0313908905.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
}
#[test]
fn test_0702269893() {
let document = include_str!("../../fixtures/konsumentinfo/0702269893.html");
let expected = Entry {
messages: vec!["Hydroscand AB".to_string()],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
messages:
- Hydroscand AB
history: []
comments: []"###);
}
#[test]
fn test_0726443387() {
let document = include_str!("../../fixtures/konsumentinfo/0726443387.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
}
#[test]
fn test_0751793426() {
let document = include_str!("../../fixtures/konsumentinfo/0751793426.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
}
#[test]
fn test_0751793483() {
let document = include_str!("../../fixtures/konsumentinfo/0751793483.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
}
#[test]
fn test_0751793499() {
let document = include_str!("../../fixtures/konsumentinfo/0751793499.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
};
assert_eq!(from_html(&document), Ok(expected));
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
}
}