Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/piquelctl/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,10 @@ pub(crate) struct CreateArgs {
/// Make the environment promoted: it never builds, and only receives
/// releases promoted from this environment of the application, given by
/// name or stable ID, with `env promote`.
#[arg(long, value_name = "ENV", conflicts_with = "branch")]
// It also conflicts with `--commit`: clap skips `--commit`'s
// `requires = "branch"` once an argument conflicting with `--branch` is
// present.
#[arg(long, value_name = "ENV", conflicts_with_all = ["branch", "commit"])]
promote_from: Option<String>,
#[command(flatten)]
change: ChangeFlags,
Expand Down
5 changes: 4 additions & 1 deletion apps/piquelctl/src/previews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ pub(crate) struct DeployArgs {
/// Application name or stable ID.
application: String,
/// Preview ID, slug, or branch. Omit it with `--local`.
#[arg(required_unless_present = "local", conflicts_with = "local")]
// The preview also conflicts with the `--local` options, the
// `SnapshotArgs` group: clap skips their `requires = "local"` once an
// argument conflicting with `--local` is present.
#[arg(required_unless_present = "local", conflicts_with_all = ["local", "SnapshotArgs"])]
preview: Option<String>,
/// The preview's slot. Give it to address a preview with a slot by its
/// branch, or to choose the preview `--local` deploys to.
Expand Down
88 changes: 88 additions & 0 deletions apps/piquelctl/tests/cli/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,94 @@ fn env_commands_target_the_named_environment() {
let _ = server.finish();
}

/// Asserts `arguments` are a usage error naming `flag`, refused before the
/// daemon is contacted.
fn assert_usage_error(arguments: &[&str], flag: &str) {
let output = support::command()
.arg("--json")
.args(arguments)
.output()
.unwrap();
assert_eq!(output.status.code(), Some(2), "{arguments:?}");
let error = support::json_error(&output);
assert_eq!(error["code"], "usage", "{arguments:?}");
assert!(error["message"].as_str().unwrap().contains(flag), "{error}");
}

#[test]
fn local_snapshot_flags_are_refused_with_a_preview() {
let deploy = [
"preview",
"deploy",
"app-notes-01",
"notes-feat-login-0a1b2c",
];
for flag in [
&["--branch", "feat"][..],
&["--full-history"],
&["--allow-secret-files"],
] {
assert_usage_error(&[&deploy[..], flag].concat(), flag[0]);
}

let server = start_server(false, 2, move |request| match request.path.as_str() {
"/api/v1/applications/app-notes-01" => Reply::json(notes_with_a_preview()),
"/api/v1/previews/env-preview-01/deploy" => {
assert_eq!(request.method, "POST");
Reply::accepted(accepted("env-preview-01"))
}
path => panic!("unexpected path {path}"),
});
let output = run(&server, &[&deploy[..], &["--no-wait"]].concat());
assert_eq!(
assert_json_success(&output)["environment_id"],
"env-preview-01"
);
let _ = server.finish();
}

#[test]
fn a_promoted_environment_refuses_a_pinned_commit() {
let commit = "a".repeat(40);
assert_usage_error(
&[
"env",
"create",
"app-notes-01",
"qa",
"--promote-from",
"staging",
"--commit",
&commit,
],
"--commit",
);

let server = request_server(
app_view("app-notes-01", "notes"),
"POST",
"/api/v1/applications/app-notes-01/environments",
json!({"name": "qa", "branch": "release", "commit": commit, "expected_generation": 1}),
Reply::json(environment("app-notes-01", "env-qa-01", "qa")),
);
let output = run(
&server,
&[
"env",
"create",
"app-notes-01",
"qa",
"--branch",
"release",
"--commit",
&commit,
"--yes",
],
);
assert_eq!(assert_json_success(&output)["name"], "qa");
let _ = server.finish();
}

#[test]
fn deleting_an_application_with_several_environments_names_every_one() {
let server = start_server(false, usize::MAX, move |request| {
Expand Down