use std::path::PathBuf;
use crate::cli::testing::{Row, build, check};
use crate::command::{RegistryLogin, RegistryLogout};
#[test]
fn registry_login_maps_every_flag_and_sends_the_password_on_stdin() {
let table: Vec<Row<RegistryLogin>> = vec![
(
RegistryLogin::new("ghcr.io"),
&["registry", "login", "ghcr.io"],
None,
),
(
RegistryLogin {
username: Some("me".into()),
password: Some("tok3n".into()),
..RegistryLogin::new("ghcr.io")
},
&[
"registry",
"login",
"ghcr.io",
"--username",
"me",
"--password-stdin",
],
Some("tok3n"),
),
(
RegistryLogin {
cert_file: Some(PathBuf::from("/c")),
key_file: Some(PathBuf::from("/k")),
ca_file: Some(PathBuf::from("/ca")),
insecure: true,
plain_http: true,
..RegistryLogin::new("localhost:5000")
},
&[
"registry",
"login",
"localhost:5000",
"--cert-file",
"/c",
"--key-file",
"/k",
"--ca-file",
"/ca",
"--insecure",
"--plain-http",
],
None,
),
];
let secret = RegistryLogin {
password: Some("tok3n".into()),
..RegistryLogin::new("ghcr.io")
};
check(table);
assert!(!build(&secret).args.join(" ").contains("tok3n"));
}
#[test]
fn registry_logout_takes_the_host() {
check(vec![(
RegistryLogout::new("ghcr.io"),
&["registry", "logout", "ghcr.io"],
None,
)]);
}