Skip to content

Commit 6c7cc54

Browse files
author
Norbert Kamiński
committed
cli.rs: Test parsing of error details in JSON format
Some network error such as SSL has no status code but it can be identified by error status details. This patch adds a test case to verify if the error details are parsed properly in the json format. Signed-off-by: Norbert Kamiński <[email protected]>
1 parent 40ccaa5 commit 6c7cc54

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test detailed JSON output error
2+
3+
This file is used to test if the error details are parsed properly in the json
4+
format.
5+
6+
[The website](https://expired.badssl.com/) produce SSL expired certificate
7+
error. Such network error has no status code but it can be identified by error
8+
status details.

lychee-bin/tests/cli.rs

+33
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,39 @@ mod cli {
133133
Ok(())
134134
}
135135

136+
#[test]
137+
fn test_detailed_json_output_on_error() -> Result<()> {
138+
let test_path =
139+
fixtures_path().join("TEST_DETAILED_JSON_OUTPUT_ERROR.md");
140+
141+
let mut cmd = main_command();
142+
cmd.arg("--format")
143+
.arg("json")
144+
.arg(&test_path)
145+
.assert()
146+
.failure()
147+
.code(2);
148+
149+
let output = cmd.output()?;
150+
151+
// Check that the output is valid JSON
152+
assert!(serde_json::from_slice::<Value>(&output.stdout).is_ok());
153+
154+
// Parse site error status from the fail_map
155+
let output_json: Value =
156+
serde_json::from_slice::<Value>(&output.stdout).unwrap();
157+
let site_error_status =
158+
&output_json["fail_map"][&test_path.to_str().unwrap()][0]["status"];
159+
160+
assert_eq!(
161+
"error:0A000086:SSL routines:tls_post_process_server_certificate:\
162+
certificate verify failed:../ssl/statem/statem_clnt.c:1883: \
163+
(certificate has expired)",
164+
site_error_status["details"]
165+
);
166+
Ok(())
167+
}
168+
136169
#[test]
137170
fn test_exclude_all_private() -> Result<()> {
138171
test_json_output!(

0 commit comments

Comments
 (0)