use super::*;
#[test]
fn rollback_flags_map_to_argv() {
let table: [FlagRow<Rollback>; 14] = [
("none", |_| {}, &[]),
("revision", |c| c.revision = Some(Revision(3)), &[]),
(
"cleanup-on-fail",
|c| c.cleanup_on_fail = true,
&["--cleanup-on-fail"],
),
(
"description",
|c| c.description = Some("back".into()),
&["--description", "back"],
),
(
"dry-run",
|c| c.dry_run = Some(DryRun::Server),
&["--dry-run=server"],
),
(
"force-replace",
|c| c.force = Some(Force::Replace),
&["--force-replace"],
),
(
"force-conflicts",
|c| c.force = Some(Force::Conflicts),
&["--force-conflicts"],
),
(
"history-max",
|c| c.history_max = Some(5),
&["--history-max", "5"],
),
("no-hooks", |c| c.no_hooks = true, &["--no-hooks"]),
(
"server-side",
|c| c.server_side = Some(ServerSide::Auto),
&["--server-side=auto"],
),
(
"timeout",
|c| c.timeout = Some(Duration::from_secs(90)),
&["--timeout", "90s"],
),
(
"wait",
|c| c.wait = Some(WaitStrategy::Legacy),
&["--wait=legacy"],
),
(
"wait-for-jobs",
|c| c.wait_for_jobs = true,
&["--wait-for-jobs"],
),
(
"combined",
|c| {
c.no_hooks = true;
c.wait = Some(WaitStrategy::Watcher);
},
&["--no-hooks", "--wait=watcher"],
),
];
check_flags(
&Rollback::new("web"),
&["rollback", "web"],
&[],
&table[..1],
);
check_flags(
&Rollback::new("web"),
&["rollback", "web"],
&[],
&table[2..],
);
assert_eq!(
argv(&Rollback {
revision: Some(Revision(3)),
..Rollback::new("web")
}),
["rollback", "web", "3"]
);
}
#[test]
fn uninstall_flags_map_to_argv() {
let table: [FlagRow<Uninstall>; 11] = [
("none", |_| {}, &[]),
("more releases", |c| c.releases.push("other".into()), &[]),
(
"cascade background",
|c| c.cascade = Some(Cascade::Background),
&["--cascade=background"],
),
(
"cascade orphan",
|c| c.cascade = Some(Cascade::Orphan),
&["--cascade=orphan"],
),
(
"cascade foreground",
|c| c.cascade = Some(Cascade::Foreground),
&["--cascade=foreground"],
),
(
"description",
|c| c.description = Some("bye".into()),
&["--description", "bye"],
),
("dry-run", |c| c.dry_run = true, &["--dry-run"]),
(
"ignore-not-found",
|c| c.ignore_not_found = true,
&["--ignore-not-found"],
),
(
"keep-history",
|c| c.keep_history = true,
&["--keep-history"],
),
("no-hooks", |c| c.no_hooks = true, &["--no-hooks"]),
(
"timeout and wait",
|c| {
c.timeout = Some(Duration::from_secs(60));
c.wait = Some(WaitStrategy::Watcher);
},
&["--timeout", "60s", "--wait=watcher"],
),
];
check_flags(
&Uninstall::new("web"),
&["uninstall", "web"],
&[],
&table[..1],
);
check_flags(
&Uninstall::new("web"),
&["uninstall", "web"],
&[],
&table[2..],
);
assert_eq!(
argv(&Uninstall {
releases: vec!["a".into(), "b".into()],
..Uninstall::new("a")
}),
["uninstall", "a", "b"]
);
}
#[test]
fn test_status_history_and_list_map_to_argv() {
let rev = Some(Revision(2));
let all_list = List {
all_namespaces: true,
date: true,
deployed: true,
failed: true,
filter: Some("^web".into()),
max: Some(10),
offset: Some(5),
pending: true,
reverse: true,
selector: Some("a=b".into()),
superseded: true,
uninstalled: true,
uninstalling: true,
};
assert_eq!(
argv(&Test {
filter: vec!["name=a".into(), "!name=b".into()],
logs: true,
timeout: Some(Duration::from_secs(30)),
..Test::new("web")
}),
[
"test",
"web",
"--filter",
"name=a",
"--filter",
"!name=b",
"--logs",
"--timeout",
"30s"
]
);
assert_eq!(argv(&Test::new("web")), ["test", "web"]);
assert_eq!(argv(&Status::new("web")), ["status", "web", "-o", "json"]);
assert_eq!(
argv(&Status {
revision: rev,
..Status::new("web")
}),
["status", "web", "--revision", "2", "-o", "json"]
);
assert_eq!(
argv(&History {
max: Some(3),
show_rollback_revision: true,
..History::new("web")
}),
[
"history",
"web",
"--max",
"3",
"--show-rollback-revision",
"-o",
"json"
]
);
assert_eq!(argv(&History::new("web")), ["history", "web", "-o", "json"]);
assert_eq!(argv(&List::new()), ["list", "-o", "json"]);
assert_eq!(
argv(&all_list),
[
"list",
"--all-namespaces",
"--date",
"--deployed",
"--failed",
"--filter",
"^web",
"--max",
"10",
"--offset",
"5",
"--pending",
"--reverse",
"--selector",
"a=b",
"--superseded",
"--uninstalled",
"--uninstalling",
"-o",
"json"
]
);
}
#[test]
fn get_commands_map_to_argv() {
let rev = Some(Revision(2));
assert_eq!(
argv(&GetValues {
all: true,
revision: rev,
..GetValues::new("web")
}),
[
"get",
"values",
"web",
"--all",
"--revision",
"2",
"-o",
"json"
]
);
assert_eq!(
argv(&GetValues::new("web")),
["get", "values", "web", "-o", "json"]
);
assert_eq!(
argv(&GetMetadata {
revision: rev,
..GetMetadata::new("web")
}),
["get", "metadata", "web", "--revision", "2", "-o", "json"]
);
assert_eq!(
argv(&GetAll {
revision: rev,
template: Some("{{.Release.Name}}".into()),
..GetAll::new("web")
}),
[
"get",
"all",
"web",
"--revision",
"2",
"--template",
"{{.Release.Name}}"
]
);
for (words, command) in [
(
"notes",
argv(&GetNotes {
revision: rev,
..GetNotes::new("web")
}),
),
(
"hooks",
argv(&GetHooks {
revision: rev,
..GetHooks::new("web")
}),
),
(
"manifest",
argv(&GetManifest {
revision: rev,
..GetManifest::new("web")
}),
),
] {
assert_eq!(command, ["get", words, "web", "--revision", "2"]);
}
}