File: snapshot_delete_spec.rb

package info (click to toggle)
ruby-fission 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 4,664; makefile: 10
file content (74 lines) | stat: -rw-r--r-- 2,343 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'spec_helper'

describe Fission::Command::SnapshotDelete do
  include_context 'command_setup'

  before do
    @target_vm = ['foo']
    Fission::VM.stub(:new).and_return(@vm_mock)

    @snap_delete_response_mock = double('snap_delete_response')

    @vm_mock.stub(:name).and_return(@target_vm.first)
  end

  describe 'command_name' do
    it 'should return the pretty command name' do
      Fission::Command::SnapshotDelete.new.command_name.should == 'snapshot delete'
    end
  end

  describe 'execute' do
    subject { Fission::Command::SnapshotDelete }

    [ [], ['foo'], ['--bar'] ].each do |args|
      it_should_not_accept_arguments_of args, 'snapshot delete'
    end

    it "should output an error and the help when no snapshot name is passed in" do
      Fission::Command::SnapshotDelete.should_receive(:help)

      command = Fission::Command::SnapshotDelete.new @target_vm
      lambda { command.execute }.should raise_error SystemExit

      @string_io.string.should match /Incorrect arguments for snapshot delete command/
    end

    it 'should delete a new snapshot with the provided name' do
      @snap_delete_response_mock.stub_as_successful []

      @vm_mock.should_receive(:delete_snapshot).
               with('snap_1').
               and_return(@snap_delete_response_mock)

      command = Fission::Command::SnapshotDelete.new @target_vm << 'snap_1'
      command.execute

      @string_io.string.should match /Deleting snapshot/
      @string_io.string.should match /Snapshot 'snap_1' deleted/
    end

    it 'should output an error and exit if there was an error creating the snapshot' do
      @snap_delete_response_mock.stub_as_unsuccessful

      @vm_mock.should_receive(:delete_snapshot).
               with('snap_1').
               and_return(@snap_delete_response_mock)

      command = Fission::Command::SnapshotDelete.new @target_vm << 'snap_1'
      lambda { command.execute }.should raise_error SystemExit

      @string_io.string.should match /Deleting snapshot/
      @string_io.string.should match /There was an error deleting the snapshot.+it blew up.+/m
    end

  end

  describe 'help' do
    it 'should output info for this command' do
      output = Fission::Command::SnapshotDelete.help

      output.should match /fission snapshot delete TARGET_VM SNAPSHOT_NAME/
    end
  end
end