tests: Add pretty_assertions crate and example.com test

This commit is contained in:
cohenarthur 2020-04-09 11:36:49 +02:00
parent 58f5710cb8
commit a6bd14a323
3 changed files with 1723 additions and 1 deletions

1665
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -7,6 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
structopt = { version = "0.3" }
structopt = "0.3"
reqwest = "0.9.22"
regex = "1"
pretty_assertions = "0.6.1"

View file

@ -10,6 +10,8 @@ pub fn download_url(url: Url) -> Result<String, reqwest::Error> {
mod tests {
use super::*;
use pretty_assertions::{assert_eq, assert_ne};
#[test]
fn test_download_url() {
let url: Url = Url::parse("https://lwn.net").unwrap();
@ -18,4 +20,58 @@ mod tests {
_ => {}
}
}
#[test]
fn test_url_content() {
let url: Url = Url::parse("https://example.com").unwrap();
match download_url(url) {
Err(e) => assert!(false, "Fail to download lwn.net: {:?}", e),
Ok(content) => assert_eq!(content, "<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset=\"utf-8\" />
<meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />
<style type=\"text/css\">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>
</div>
</body>
</html>\n"),
}
}
}