mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-17 05:00:26 +00:00
Fix format option in configuration file (#1547)
This commit is contained in:
parent
e43086c2e9
commit
812941c2aa
3 changed files with 26 additions and 1 deletions
1
fixtures/configs/format.toml
vendored
Normal file
1
fixtures/configs/format.toml
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
format = "json"
|
||||
|
|
@ -46,9 +46,10 @@ const TIMEOUT_STR: &str = concatcp!(DEFAULT_TIMEOUT_SECS);
|
|||
const RETRY_WAIT_TIME_STR: &str = concatcp!(DEFAULT_RETRY_WAIT_TIME_SECS);
|
||||
|
||||
/// The format to use for the final status report
|
||||
#[derive(Debug, Deserialize, Default, Clone, Display, EnumIter, VariantNames)]
|
||||
#[derive(Debug, Deserialize, Default, Clone, Display, EnumIter, VariantNames, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum StatsFormat {
|
||||
#[default]
|
||||
Compact,
|
||||
|
|
@ -544,6 +545,7 @@ impl Config {
|
|||
exclude_link_local: false;
|
||||
exclude_loopback: false;
|
||||
exclude_mail: false;
|
||||
format: StatsFormat::default();
|
||||
remap: Vec::<String>::new();
|
||||
fallback_extensions: Vec::<String>::new();
|
||||
header: Vec::<String>::new();
|
||||
|
|
|
|||
|
|
@ -1723,4 +1723,26 @@ mod cli {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_json_format_in_config() -> Result<()> {
|
||||
let mock_server = mock_server!(StatusCode::OK);
|
||||
let config = fixtures_path().join("configs").join("format.toml");
|
||||
let mut cmd = main_command();
|
||||
cmd.arg("--config")
|
||||
.arg(config)
|
||||
.arg("-")
|
||||
.write_stdin(mock_server.uri())
|
||||
.env_clear()
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
// Check that the output is in JSON format
|
||||
let output = cmd.output().unwrap();
|
||||
let output = std::str::from_utf8(&output.stdout).unwrap();
|
||||
let json: serde_json::Value = serde_json::from_str(output)?;
|
||||
assert_eq!(json["total"], 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue