Skip to content

Commit f45a797

Browse files
authored
rust(fix): allow partial sift-cli config updates (#556)
1 parent 9431376 commit f45a797

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

rust/crates/sift_cli/src/cmd/config.rs renamed to rust/crates/sift_cli/src/cmd/config/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(test)]
2+
mod tests;
3+
14
use crate::BIN_NAME;
25
use anyhow::{Context, Result, anyhow};
36
use crossterm::style::Stylize;
@@ -205,6 +208,6 @@ fn is_update_empty(args: &ConfigUpdateArgs) -> bool {
205208
..
206209
} = args;
207210
grpc_uri.as_ref().is_none_or(|s| s.is_empty())
208-
|| rest_uri.as_ref().is_none_or(|s| s.is_empty())
209-
|| api_key.as_ref().is_none_or(|s| s.is_empty())
211+
&& rest_uri.as_ref().is_none_or(|s| s.is_empty())
212+
&& api_key.as_ref().is_none_or(|s| s.is_empty())
210213
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
mod test_is_update_empty {
2+
use super::super::is_update_empty;
3+
use crate::cli::ConfigUpdateArgs;
4+
5+
fn args(
6+
grpc_uri: Option<&str>,
7+
rest_uri: Option<&str>,
8+
api_key: Option<&str>,
9+
) -> ConfigUpdateArgs {
10+
ConfigUpdateArgs {
11+
interactive: false,
12+
grpc_uri: grpc_uri.map(String::from),
13+
rest_uri: rest_uri.map(String::from),
14+
api_key: api_key.map(String::from),
15+
}
16+
}
17+
18+
#[test]
19+
fn no_flags_is_empty() {
20+
assert!(is_update_empty(&args(None, None, None)));
21+
}
22+
23+
#[test]
24+
fn all_empty_strings_is_empty() {
25+
assert!(is_update_empty(&args(Some(""), Some(""), Some(""))));
26+
}
27+
28+
#[test]
29+
fn any_single_flag_is_not_empty() {
30+
assert!(!is_update_empty(&args(Some("g"), None, None)));
31+
assert!(!is_update_empty(&args(None, Some("r"), None)));
32+
assert!(!is_update_empty(&args(None, None, Some("k"))));
33+
}
34+
35+
#[test]
36+
fn all_flags_set_is_not_empty() {
37+
assert!(!is_update_empty(&args(Some("g"), Some("r"), Some("k"))));
38+
}
39+
}

0 commit comments

Comments
 (0)