Files
ubicloud/spec/routes/api/cli/vm/destroy_spec.rb
Jeremy Evans 355f7d3f97 Restructure CLI help to support command descriptions
This provides descriptions for all commands.  Command help now
uses the following format:

```
DESCRIPTION

Usage:
    BANNERS

Commands:
    COMMAND    DESCRIPTION

Post Commands:
    COMMAND    DESCRIPTION

Options:
    OPTION     DESCRIPTION

Post Options:
    OPTION     DESCRIPTION
```

This required substantial changes to rodish, so this updates to the
current head of rodish.

Other minor changes:

* Use "virtual machine" instead of "VM" in command help

* Use "command" or "post-command" instead of "subcommand" in usage

* Use "ps-id" instead of "subnet-id" in {at,de}tach-subnet command usage

* Use "rule-id" instead of "id" in delete pg firewall rule usage

* Use "md-id" instead of "id" in delete pg metric destination usage

* Avoid literal "Usage: " in help -u output
2025-03-13 09:20:15 -07:00

42 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli vm destroy" do
before do
expect(Vm.count).to eq 0
expect(PrivateSubnet.count).to eq 0
cli(%w[vm eu-central-h1/test-vm create a])
expect(Vm.count).to eq 1
@vm = Vm.first
expect(@vm).to be_a Vm
end
it "destroys vm directly if -f option is given" do
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).to be_empty
expect(cli(%w[vm eu-central-h1/test-vm destroy -f])).to eq "Virtual machine, if it exists, is now scheduled for destruction\n"
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).not_to be_empty
end
it "asks for confirmation if -f option is not given" do
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).to be_empty
expect(cli(%w[vm eu-central-h1/test-vm destroy], confirm_prompt: "Confirmation")).to eq <<~END
Destroying this virtual machine is not recoverable.
Enter the following to confirm destruction of the virtual machine: #{@vm.name}
END
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).to be_empty
end
it "works on correct confirmation" do
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).to be_empty
expect(cli(%w[--confirm test-vm vm eu-central-h1/test-vm destroy])).to eq "Virtual machine, if it exists, is now scheduled for destruction\n"
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).not_to be_empty
end
it "fails on incorrect confirmation" do
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).to be_empty
expect(cli(%w[--confirm foo vm eu-central-h1/test-vm destroy], status: 400)).to eq "! Confirmation of virtual machine name not successful.\n"
expect(Semaphore.where(strand_id: @vm.id, name: "destroy")).to be_empty
end
end