use std::path::PathBuf;
use crate::command::{
ChartPathOptions, DependencyBuild, DependencyList, DependencyOptions, DependencyUpdate,
};
use crate::options::Secret;
#[test]
fn option_groups_build_what_the_literals_build() {
let chart_path = ChartPathOptions::builder()
.version("^2.0.0")
.verify(true)
.keyring("/keys/ring.gpg")
.repo("https://charts.example")
.username("ci")
.password("hunter2")
.plain_http(true)
.build();
let dependency = DependencyOptions::builder()
.verify(true)
.keyring("/keys/ring.gpg")
.skip_refresh(true)
.username("ci")
.password("hunter2")
.maybe_ca_file(None::<PathBuf>)
.build();
let options = DependencyOptions {
skip_refresh: true,
..DependencyOptions::default()
};
assert_builds! {
"chart path": chart_path => ChartPathOptions {
version: Some("^2.0.0".to_owned()),
verify: true,
keyring: Some(PathBuf::from("/keys/ring.gpg")),
repo: Some("https://charts.example".to_owned()),
username: Some("ci".to_owned()),
password: Some(Secret::from("hunter2")),
plain_http: true,
..ChartPathOptions::default()
};
"chart path defaults": ChartPathOptions::builder().build() => ChartPathOptions::default();
"dependency": dependency => DependencyOptions {
verify: true,
keyring: Some(PathBuf::from("/keys/ring.gpg")),
skip_refresh: true,
username: Some("ci".to_owned()),
password: Some(Secret::from("hunter2")),
..DependencyOptions::default()
};
"dependency defaults": DependencyOptions::builder().build() => DependencyOptions::default();
"dependency build": DependencyBuild::builder("chart").options(options.clone()).build()
=> DependencyBuild { options: options.clone(), ..DependencyBuild::new("chart") };
"dependency update": DependencyUpdate::builder("chart").options(options.clone()).build()
=> DependencyUpdate { options, ..DependencyUpdate::new("chart") };
"dependency list": DependencyList::builder("chart").build() => DependencyList::new("chart");
}
}
#[test]
fn the_builders_cannot_print_a_secret() {
let chart_path = ChartPathOptions::builder().password("hunter2").build();
let dependency = DependencyOptions::builder().password("hunter2").build();
assert_not_debug!(ChartPathOptions::builder().password("hunter2"));
assert_not_debug!(DependencyOptions::builder().password("hunter2"));
for shown in [format!("{chart_path:?}"), format!("{dependency:?}")] {
assert!(!shown.contains("hunter2"), "{shown}");
assert!(shown.contains("<redacted>"), "{shown}");
}
}