Skip to content

Commit

Permalink
Fix bool flag handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Sep 13, 2024
1 parent 381184c commit c5e8150
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions proxydetox/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ impl From<ArgMatches> for Options {
.cloned()
.or_else(|| which_pac_file().map(PathOrUri::Path)),
authorization,
always_use_connect: m.contains_id("always_use_connect"),
direct_fallback: m.contains_id("direct_fallback"),
always_use_connect: m.get_flag("always_use_connect"),
direct_fallback: m.get_flag("direct_fallback"),
connect_timeout: m
.get_one::<f64>("connect_timeout")
.map(|s| Duration::from_millis((*s * 1000.0) as u64))
Expand Down Expand Up @@ -435,6 +435,24 @@ mod tests {
assert!(is_file_or_http_uri("/does/not/exist").is_err());
}

#[test]
fn test_default() {
let args = Options::parse_args(&["proxydetox".into()]);
assert_eq!(args.direct_fallback, false);
assert_eq!(args.always_use_connect, false);
}

#[test]
fn test_not_default() {
let args = Options::parse_args(&[
"proxydetox".into(),
"--direct-fallback".into(),
"--always-use-connect".into(),
]);
assert_eq!(args.direct_fallback, true);
assert_eq!(args.always_use_connect, true);
}

#[test]
fn test_pac_file_path() {
let pac_file = example_pac();
Expand Down

0 comments on commit c5e8150

Please sign in to comment.