Skip to content

Commit

Permalink
add tests for reading args from config
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Aug 2, 2021
1 parent 6fbe5df commit f85c2cd
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,3 +1323,42 @@ fn accept_encoding_not_modifiable_in_download_mode() {
.assert();
mock.assert();
}

#[test]
fn read_args_from_config() {
let config_dir = tempdir().unwrap();
File::create(config_dir.path().join("config.json")).unwrap();
std::fs::write(
config_dir.path().join("config.json"),
serde_json::json!({"default_options": ["--form"]}).to_string(),
)
.unwrap();

get_command()
.env("XH_CONFIG_DIR", config_dir.path())
.arg(":")
.arg("--offline")
.arg("--print=B")
.arg("sort=asc")
.arg("limit=100")
.assert()
.stdout("sort=asc&limit=100\n\n");
}

#[test]
fn warns_if_config_is_invalid() {
let config_dir = tempdir().unwrap();
File::create(config_dir.path().join("config.json")).unwrap();
std::fs::write(
config_dir.path().join("config.json"),
serde_json::json!({"default_options": "--form"}).to_string(),
)
.unwrap();

get_command()
.env("XH_CONFIG_DIR", config_dir.path())
.arg(":")
.arg("--offline")
.assert()
.stderr(contains("Unable to parse config file"));
}

0 comments on commit f85c2cd

Please sign in to comment.