fission 0.2.0 → 0.3.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,8 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::Clone do
4
- before :all do
4
+ before do
5
5
  @vm_info = ['foo', 'bar']
6
- end
7
-
8
- before :each do
9
6
  @string_io = StringIO.new
10
7
  Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
11
8
  end
@@ -36,7 +33,6 @@ describe Fission::Command::Clone do
36
33
  @string_io.string.should match /Unable to find the source vm #{@vm_info.first}/
37
34
  end
38
35
 
39
-
40
36
  it "should output an error and exit if the target vm already exists" do
41
37
  @vm_info.each do |vm|
42
38
  Fission::VM.should_receive(:exists?).with(vm).and_return(true)
@@ -84,7 +80,7 @@ describe Fission::Command::Clone do
84
80
  it 'should output info for this command' do
85
81
  output = Fission::Command::Clone.help
86
82
 
87
- output.should match /clone source_vm target_vm/
83
+ output.should match /clone source_vm target_vm.+--start/m
88
84
  end
89
85
  end
90
86
  end
@@ -0,0 +1,109 @@
1
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
2
+
3
+ describe Fission::Command::Delete do
4
+ before do
5
+ @target_vm = ['foo']
6
+ @string_io = StringIO.new
7
+ Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
8
+ end
9
+
10
+ describe "execute" do
11
+ it "should output an error and the help when no VM argument is passed in" do
12
+ Fission::Command::Delete.should_receive(:help)
13
+
14
+ lambda {
15
+ command = Fission::Command::Delete.new
16
+ command.execute
17
+ }.should raise_error SystemExit
18
+
19
+ @string_io.string.should match /Incorrect arguments for delete command/
20
+ end
21
+
22
+ it "should output an error and exit if it can't find the target vm" do
23
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(false)
24
+
25
+ lambda {
26
+ command = Fission::Command::Delete.new @target_vm
27
+ command.execute
28
+ }.should raise_error SystemExit
29
+
30
+ @string_io.string.should match /Unable to find target vm #{@target_vm}/
31
+ end
32
+
33
+ it "should try to delete the vm if it exists" do
34
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
35
+ Fission::Fusion.should_receive(:is_running?).and_return(false)
36
+ Fission::VM.should_receive(:delete).with(@target_vm.first)
37
+ command = Fission::Command::Delete.new @target_vm
38
+ command.execute
39
+ @string_io.string.should match /Deletion complete/
40
+ end
41
+
42
+ it 'should output an error and exit if the VM is running' do
43
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
44
+ Fission::VM.should_receive(:all_running).and_return(['foo', 'bar'])
45
+ lambda {
46
+ command = Fission::Command::Delete.new @target_vm
47
+ command.execute
48
+ }.should raise_error SystemExit
49
+
50
+ @string_io.string.should match /VM is currently running/
51
+ @string_io.string.should match /Either stop\/suspend the VM or use '--force' and try again/
52
+ end
53
+
54
+ it 'should output an error and exit if the fusion app is running' do
55
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
56
+ Fission::VM.should_receive(:all_running).and_return(['bar'])
57
+ Fission::Fusion.should_receive(:is_running?).and_return(true)
58
+
59
+ lambda {
60
+ command = Fission::Command::Delete.new @target_vm
61
+ command.execute
62
+ }.should raise_error SystemExit
63
+
64
+ @string_io.string.should match /Fusion GUI is currently running/
65
+ @string_io.string.should match /Either exit the Fusion GUI or use '--force' and try again/
66
+ @string_io.string.should match /NOTE: Forcing a VM deletion with the Fusion GUI running may not clean up all of the VM metadata/
67
+ end
68
+
69
+ describe 'with --force' do
70
+ before do
71
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
72
+ end
73
+
74
+ it "should stop the VM if it's running and then delete it" do
75
+ @stop_cmd_mock = mock('stop_cmd')
76
+ @stop_cmd_mock.should_receive(:execute)
77
+ Fission::VM.should_receive(:all_running).and_return(['foo', 'bar'])
78
+ Fission::Fusion.should_receive(:is_running?).and_return(false)
79
+ Fission::Command::Stop.should_receive(:new).with(@target_vm).
80
+ and_return(@stop_cmd_mock)
81
+ command = Fission::Command::Delete.new @target_vm << '--force'
82
+ command.execute
83
+ @string_io.string.should match /VM is currently running/
84
+ @string_io.string.should match /Going to stop it/
85
+ @string_io.string.should match /Deletion complete/
86
+ end
87
+
88
+ it 'should output a warning about fusion metadata issue and then delete the VM' do
89
+ Fission::VM.should_receive(:all_running).and_return(['bar'])
90
+ Fission::Fusion.should_receive(:is_running?).and_return(true)
91
+ command = Fission::Command::Delete.new @target_vm << '--force'
92
+ command.execute
93
+ @string_io.string.should match /Fusion GUI is currently running/
94
+ @string_io.string.should match /metadata for the VM may not be removed completely/
95
+ @string_io.string.should match /Deletion complete/
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ describe 'help' do
102
+ it 'should output info for this command' do
103
+ output = Fission::Command::Delete.help
104
+
105
+ output.should match /delete target_vm \[--force\]/
106
+ output.should match /--force/
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,88 @@
1
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
2
+
3
+ describe Fission::Command::SnapshotCreate do
4
+ before do
5
+ @target_vm = ['foo']
6
+ @vm_mock = mock('vm_mock')
7
+ Fission::VM.stub!(:new).and_return(@vm_mock)
8
+ @string_io = StringIO.new
9
+ Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
10
+ end
11
+
12
+ describe 'execute' do
13
+ it "should output an error and the help when no vm name is passed in" do
14
+ Fission::Command::SnapshotCreate.should_receive(:help)
15
+
16
+ lambda {
17
+ command = Fission::Command::SnapshotCreate.new
18
+ command.execute
19
+ }.should raise_error SystemExit
20
+
21
+ @string_io.string.should match /Incorrect arguments for snapshot create command/
22
+ end
23
+
24
+ it "should output an error and the help when no snapshot name is passed in" do
25
+ Fission::Command::SnapshotCreate.should_receive(:help)
26
+
27
+ lambda {
28
+ command = Fission::Command::SnapshotCreate.new @target_vm
29
+ command.execute
30
+ }.should raise_error SystemExit
31
+
32
+ @string_io.string.should match /Incorrect arguments for snapshot create command/
33
+ end
34
+
35
+ it "should output an error and exit if it can't find the target vm" do
36
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(false)
37
+
38
+ lambda {
39
+ command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
40
+ command.execute
41
+ }.should raise_error SystemExit
42
+
43
+ @string_io.string.should match /Unable to find the VM #{@target_vm.first}/
44
+ end
45
+
46
+ it 'should output an error and exit if the VM is not running' do
47
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
48
+ Fission::VM.should_receive(:all_running).and_return([])
49
+ lambda {
50
+ command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
51
+ command.execute
52
+ }.should raise_error SystemExit
53
+
54
+ @string_io.string.should match /VM 'foo' is not running/
55
+ @string_io.string.should match /A snapshot cannot be created unless the VM is running/
56
+ end
57
+
58
+ it "should output an error and exit if there is already a snapshot with the provided name" do
59
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
60
+ Fission::VM.should_receive(:all_running).and_return(['foo'])
61
+ @vm_mock.should_receive(:snapshots).and_return(['snap_1'])
62
+ lambda {
63
+ command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
64
+ command.execute
65
+ }.should raise_error SystemExit
66
+
67
+ @string_io.string.should match /VM 'foo' already has a snapshot named 'snap_1'/
68
+ end
69
+
70
+ it 'should create a new snapshot with the provided name' do
71
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
72
+ Fission::VM.should_receive(:all_running).and_return(['foo'])
73
+ @vm_mock.should_receive(:snapshots).and_return([])
74
+ @vm_mock.should_receive(:create_snapshot).with('snap_1')
75
+ command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
76
+ command.execute
77
+ @string_io.string.should match /Creating snapshot/
78
+ end
79
+ end
80
+
81
+ describe 'help' do
82
+ it 'should output info for this command' do
83
+ output = Fission::Command::SnapshotCreate.help
84
+
85
+ output.should match /snapshot create my_vm snapshot_1/
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
2
+
3
+ describe Fission::Command::SnapshotList do
4
+ before do
5
+ @target_vm = ['foo']
6
+ @vm_mock = mock('vm_mock')
7
+ Fission::VM.stub!(:new).and_return(@vm_mock)
8
+ @string_io = StringIO.new
9
+ Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
10
+ end
11
+
12
+ describe 'execute' do
13
+ it "should output an error and the help when no VM argument is passed in" do
14
+ Fission::Command::SnapshotList.should_receive(:help)
15
+
16
+ lambda {
17
+ command = Fission::Command::SnapshotList.new
18
+ command.execute
19
+ }.should raise_error SystemExit
20
+
21
+ @string_io.string.should match /Incorrect arguments for snapshot list command/
22
+ end
23
+
24
+ it "should output an error and exit if it can't find the target vm" do
25
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(false)
26
+
27
+ lambda {
28
+ command = Fission::Command::SnapshotList.new @target_vm
29
+ command.execute
30
+ }.should raise_error SystemExit
31
+
32
+ @string_io.string.should match /Unable to find the VM #{@target_vm.first}/
33
+ end
34
+
35
+ it 'should output the list of snapshots if any exist' do
36
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
37
+ @vm_mock.should_receive(:snapshots).and_return(['snap 1', 'snap 2', 'snap 3'])
38
+ command = Fission::Command::SnapshotList.new @target_vm
39
+ command.execute
40
+
41
+ @string_io.string.should match /snap 1\nsnap 2\nsnap 3\n/
42
+ end
43
+
44
+ it 'should output that it could not find any snapshots if none exist' do
45
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
46
+ @vm_mock.should_receive(:snapshots).and_return([])
47
+ command = Fission::Command::SnapshotList.new @target_vm
48
+ command.execute
49
+
50
+ @string_io.string.should match /No snapshots found for VM '#{@target_vm.first}'/
51
+ end
52
+ end
53
+
54
+ describe 'help' do
55
+ it 'should output info for this command' do
56
+ output = Fission::Command::SnapshotList.help
57
+
58
+ output.should match /snapshot list/
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
2
+
3
+ describe Fission::Command::SnapshotRevert do
4
+ before do
5
+ @target_vm = ['foo']
6
+ @vm_mock = mock('vm_mock')
7
+ Fission::VM.stub!(:new).and_return(@vm_mock)
8
+ @string_io = StringIO.new
9
+ Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
10
+ end
11
+
12
+ describe 'execute' do
13
+ it "should output an error and the help when no vm name is passed in" do
14
+ Fission::Command::SnapshotRevert.should_receive(:help)
15
+
16
+ lambda {
17
+ command = Fission::Command::SnapshotRevert.new
18
+ command.execute
19
+ }.should raise_error SystemExit
20
+
21
+ @string_io.string.should match /Incorrect arguments for snapshot revert command/
22
+ end
23
+
24
+ it "should output an error and the help when no snapshot name is passed in" do
25
+ Fission::Command::SnapshotRevert.should_receive(:help)
26
+
27
+ lambda {
28
+ command = Fission::Command::SnapshotRevert.new @target_vm
29
+ command.execute
30
+ }.should raise_error SystemExit
31
+
32
+ @string_io.string.should match /Incorrect arguments for snapshot revert command/
33
+ end
34
+
35
+ it "should output an error and exit if it can't find the target vm" do
36
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(false)
37
+
38
+ lambda {
39
+ command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
40
+ command.execute
41
+ }.should raise_error SystemExit
42
+
43
+ @string_io.string.should match /Unable to find the VM #{@target_vm.first}/
44
+ end
45
+
46
+ it "should output an error and exit if it can't find the snapshot" do
47
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
48
+ Fission::Fusion.should_receive(:is_running?).and_return(false)
49
+ @vm_mock.should_receive(:snapshots).and_return([])
50
+
51
+ lambda {
52
+ command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
53
+ command.execute
54
+ }.should raise_error SystemExit
55
+
56
+ @string_io.string.should match /Unable to find the snapshot 'snap_1'/
57
+ end
58
+
59
+ it 'should output an error and exit if the fusion app is running' do
60
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
61
+ Fission::Fusion.should_receive(:is_running?).and_return(true)
62
+
63
+ lambda {
64
+ command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
65
+ command.execute
66
+ }.should raise_error SystemExit
67
+
68
+ @string_io.string.should match /Fusion GUI is currently running/
69
+ @string_io.string.should match /Please exit the Fusion GUI and try again/
70
+ end
71
+
72
+ it 'should revert to the snapshot with the provided name' do
73
+ Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
74
+ Fission::Fusion.should_receive(:is_running?).and_return(false)
75
+ @vm_mock.should_receive(:snapshots).and_return(['snap_1', 'snap_2'])
76
+ @vm_mock.should_receive(:revert_to_snapshot).with('snap_1')
77
+ command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
78
+ command.execute
79
+ @string_io.string.should match /Reverting to snapshot 'snap_1'/
80
+ end
81
+ end
82
+
83
+ describe 'help' do
84
+ it 'should output info for this command' do
85
+ output = Fission::Command::SnapshotRevert.help
86
+
87
+ output.should match /snapshot revert my_vm snapshot_1/
88
+ end
89
+ end
90
+ end
@@ -1,13 +1,11 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::Start do
4
- before :all do
4
+ before do
5
5
  @vm_info = ['foo']
6
- end
7
-
8
- before :each do
9
6
  @string_io = StringIO.new
10
7
  Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
8
+ @vm_mock = mock('vm_mock')
11
9
  end
12
10
 
13
11
  describe 'execute' do
@@ -47,7 +45,6 @@ describe Fission::Command::Start do
47
45
  end
48
46
 
49
47
  it 'should try to start the vm if it is not running' do
50
- @vm_mock = mock('vm_mock')
51
48
  Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
52
49
  Fission::VM.should_receive(:all_running).and_return([])
53
50
  Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
@@ -59,13 +56,45 @@ describe Fission::Command::Start do
59
56
  @string_io.string.should match /Starting '#{@vm_info.first}'/
60
57
  end
61
58
 
59
+ describe 'with --headless' do
60
+ it 'should start the vm headless' do
61
+ Fission::Fusion.should_receive(:is_running?).and_return(false)
62
+ Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
63
+ Fission::VM.should_receive(:all_running).and_return([])
64
+ Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
65
+ @vm_mock.should_receive(:start).with(:headless => true)
66
+
67
+ command = Fission::Command::Start.new @vm_info << '--headless'
68
+ command.execute
69
+
70
+ @string_io.string.should match /Starting '#{@vm_info.first}'/
71
+ end
72
+
73
+ it 'should output an error and exit if the fusion app is running' do
74
+ Fission::Fusion.should_receive(:is_running?).and_return(true)
75
+ Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
76
+ Fission::VM.should_receive(:all_running).and_return([])
77
+ Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
78
+ @vm_mock.should_not_receive(:start)
79
+
80
+ lambda {
81
+ command = Fission::Command::Start.new @vm_info << '--headless'
82
+ command.execute
83
+ }.should raise_error SystemExit
84
+
85
+ @string_io.string.should match /Fusion GUI is currently running/
86
+ @string_io.string.should match /A VM cannot be started in headless mode when the Fusion GUI is running/
87
+ @string_io.string.should match /Exit the Fusion GUI and try again/
88
+ end
89
+ end
62
90
  end
63
91
 
64
92
  describe 'help' do
65
93
  it 'should output info for this command' do
66
94
  output = Fission::Command::Start.help
67
95
 
68
- output.should match /start vm/
96
+ output.should match /start vm \[options\]/
97
+ output.should match /--headless/
69
98
  end
70
99
  end
71
100
  end