Files
ubicloud/spec/routes/api/cli/pg/destroy_spec.rb
Jeremy Evans 94dbf5114a Require confirmation for cli vm/pg destroy commands
This requires changes to the cli at all levels, since the cli was
not originally designed to be interactive.

Have the /cli API endpoint ask for confirmation via an ubi-confirm
header.  Make bin/ubi recognize the ubi-confirm header and prompt
the user for confirmation.  The confirmation value is sent in the
top level --confirm option.

Change UbiCli.destroy, used for both vm and pg destory to support
an -f/--force option to destroy without asking for confirmation.
Unless the -f option is given, it asks for confirmation.  If
confirmation is already provided, and it is correct, it runs the
destroy command.  If the confirmation is already provided and it
is incorrect, an error is returned.

To ease implementation of this in bin/ubi, a 1.times do block is
used. If confirmation is required, argv is prepended with the
--confirm option and confirmation value, and then redo is used
to send another request.  Rubocop doesn't understand this and
tries to remove the 1.times do, breaking the code, so disable
that cop.
2025-02-13 14:41:19 -08:00

21 lines
767 B
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli pg destroy" do
before do
expect(Config).to receive(:postgres_service_project_id).and_return(@project.id).at_least(:once)
end
it "destroys PostgreSQL database" do
expect(PostgresResource.count).to eq 0
cli(%w[pg eu-central-h1/test-pg create])
expect(PostgresResource.count).to eq 1
pg = PostgresResource.first
expect(pg).to be_a PostgresResource
expect(Semaphore.where(strand_id: pg.id, name: "destroy")).to be_empty
expect(cli(%w[pg eu-central-h1/test-pg destroy -f])).to eq "PostgreSQL database, if it exists, is now scheduled for destruction"
expect(Semaphore.where(strand_id: pg.id, name: "destroy")).not_to be_empty
end
end