Add status code in Markdown output (#677)

This commit is contained in:
Walter Beller-Morales 2022-07-05 08:43:15 -04:00 committed by GitHub
parent 59ac68069b
commit 75a3da0b7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -73,8 +73,11 @@ impl Display for MarkdownResponseStats {
for response in responses {
writeln!(
f,
"* [{}]({}): {}",
response.uri, response.uri, response.status
"* [{}]({}): {} (status code: {})",
response.uri,
response.uri,
response.status,
response.status.code()
)?;
}
writeln!(f)?;
@ -102,6 +105,8 @@ impl StatsFormatter for Markdown {
#[cfg(test)]
mod tests {
use lychee_lib::{CacheStatus, InputSource, Response, ResponseBody, Status, Uri};
use super::*;
#[test]
@ -120,4 +125,37 @@ mod tests {
"#;
assert_eq!(table, expected.to_string());
}
#[test]
fn test_render_summary() {
let mut stats = ResponseStats::new();
let response = Response(
InputSource::Stdin,
ResponseBody {
uri: Uri::try_from("http://127.0.0.1").unwrap(),
status: Status::Cached(CacheStatus::Error(Some(404))),
},
);
stats.add(response);
let summary = MarkdownResponseStats(stats);
let expected = r#"## Summary
| Status | Count |
|---------------|-------|
| 🔍 Total | 1 |
| Successful | 0 |
| Timeouts | 0 |
| 🔀 Redirected | 0 |
| 👻 Excluded | 0 |
| Unknown | 0 |
| 🚫 Errors | 1 |
## Errors per input
### Errors in stdin
* [http://127.0.0.1/](http://127.0.0.1/): Cached: Error (cached) (status code: 404)
"#;
assert_eq!(summary.to_string(), expected.to_string());
}
}