vagrantup 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +17 -0
- data/README.md +45 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/bin/.gitignore +0 -0
- data/bin/vagrant +15 -0
- data/bin/vagrant-box +35 -0
- data/bin/vagrant-down +28 -0
- data/bin/vagrant-halt +29 -0
- data/bin/vagrant-init +28 -0
- data/bin/vagrant-package +30 -0
- data/bin/vagrant-reload +30 -0
- data/bin/vagrant-resume +28 -0
- data/bin/vagrant-ssh +28 -0
- data/bin/vagrant-suspend +28 -0
- data/bin/vagrant-up +30 -0
- data/config/default.rb +29 -0
- data/lib/vagrant.rb +14 -0
- data/lib/vagrant/actions/base.rb +93 -0
- data/lib/vagrant/actions/box/add.rb +22 -0
- data/lib/vagrant/actions/box/destroy.rb +14 -0
- data/lib/vagrant/actions/box/download.rb +63 -0
- data/lib/vagrant/actions/box/unpackage.rb +49 -0
- data/lib/vagrant/actions/runner.rb +128 -0
- data/lib/vagrant/actions/vm/destroy.rb +14 -0
- data/lib/vagrant/actions/vm/down.rb +12 -0
- data/lib/vagrant/actions/vm/export.rb +41 -0
- data/lib/vagrant/actions/vm/forward_ports.rb +32 -0
- data/lib/vagrant/actions/vm/halt.rb +14 -0
- data/lib/vagrant/actions/vm/import.rb +17 -0
- data/lib/vagrant/actions/vm/move_hard_drive.rb +53 -0
- data/lib/vagrant/actions/vm/package.rb +61 -0
- data/lib/vagrant/actions/vm/provision.rb +71 -0
- data/lib/vagrant/actions/vm/reload.rb +17 -0
- data/lib/vagrant/actions/vm/resume.rb +16 -0
- data/lib/vagrant/actions/vm/shared_folders.rb +69 -0
- data/lib/vagrant/actions/vm/start.rb +50 -0
- data/lib/vagrant/actions/vm/suspend.rb +16 -0
- data/lib/vagrant/actions/vm/up.rb +35 -0
- data/lib/vagrant/box.rb +129 -0
- data/lib/vagrant/busy.rb +73 -0
- data/lib/vagrant/commands.rb +174 -0
- data/lib/vagrant/config.rb +156 -0
- data/lib/vagrant/downloaders/base.rb +13 -0
- data/lib/vagrant/downloaders/file.rb +21 -0
- data/lib/vagrant/downloaders/http.rb +47 -0
- data/lib/vagrant/env.rb +140 -0
- data/lib/vagrant/ssh.rb +43 -0
- data/lib/vagrant/util.rb +45 -0
- data/lib/vagrant/vm.rb +57 -0
- data/script/vagrant-ssh-expect.sh +22 -0
- data/templates/Vagrantfile +8 -0
- data/test/test_helper.rb +91 -0
- data/test/vagrant/actions/base_test.rb +32 -0
- data/test/vagrant/actions/box/add_test.rb +37 -0
- data/test/vagrant/actions/box/destroy_test.rb +18 -0
- data/test/vagrant/actions/box/download_test.rb +118 -0
- data/test/vagrant/actions/box/unpackage_test.rb +101 -0
- data/test/vagrant/actions/runner_test.rb +236 -0
- data/test/vagrant/actions/vm/destroy_test.rb +24 -0
- data/test/vagrant/actions/vm/down_test.rb +32 -0
- data/test/vagrant/actions/vm/export_test.rb +88 -0
- data/test/vagrant/actions/vm/forward_ports_test.rb +50 -0
- data/test/vagrant/actions/vm/halt_test.rb +27 -0
- data/test/vagrant/actions/vm/import_test.rb +36 -0
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +108 -0
- data/test/vagrant/actions/vm/package_test.rb +155 -0
- data/test/vagrant/actions/vm/provision_test.rb +103 -0
- data/test/vagrant/actions/vm/reload_test.rb +44 -0
- data/test/vagrant/actions/vm/resume_test.rb +27 -0
- data/test/vagrant/actions/vm/shared_folders_test.rb +117 -0
- data/test/vagrant/actions/vm/start_test.rb +55 -0
- data/test/vagrant/actions/vm/suspend_test.rb +27 -0
- data/test/vagrant/actions/vm/up_test.rb +76 -0
- data/test/vagrant/box_test.rb +92 -0
- data/test/vagrant/busy_test.rb +81 -0
- data/test/vagrant/commands_test.rb +252 -0
- data/test/vagrant/config_test.rb +123 -0
- data/test/vagrant/downloaders/base_test.rb +20 -0
- data/test/vagrant/downloaders/file_test.rb +32 -0
- data/test/vagrant/downloaders/http_test.rb +40 -0
- data/test/vagrant/env_test.rb +293 -0
- data/test/vagrant/ssh_test.rb +95 -0
- data/test/vagrant/util_test.rb +64 -0
- data/test/vagrant/vm_test.rb +96 -0
- metadata +263 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class DestroyActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Destroy)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "executing" do
|
10
|
+
setup do
|
11
|
+
@vm.stubs(:destroy)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "invoke an around callback around the destroy" do
|
15
|
+
@mock_vm.expects(:invoke_around_callback).with(:destroy).once
|
16
|
+
@action.execute!
|
17
|
+
end
|
18
|
+
|
19
|
+
should "destroy VM and attached images" do
|
20
|
+
@vm.expects(:destroy).with(:destroy_image => true).once
|
21
|
+
@action.execute!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class DownActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Down)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "preparing" do
|
10
|
+
setup do
|
11
|
+
@vm.stubs(:running?).returns(false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup_action_expectations(order)
|
15
|
+
default_seq = sequence("default_seq")
|
16
|
+
order.each do |action|
|
17
|
+
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
should "add the destroy action alone if VM is not running" do
|
22
|
+
setup_action_expectations([Vagrant::Actions::VM::Destroy])
|
23
|
+
@action.prepare
|
24
|
+
end
|
25
|
+
|
26
|
+
should "add the halt action if the VM is running" do
|
27
|
+
@vm.expects(:running?).returns(true)
|
28
|
+
setup_action_expectations([Vagrant::Actions::VM::Halt, Vagrant::Actions::VM::Destroy])
|
29
|
+
@action.prepare
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ExportActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Export)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "executing" do
|
10
|
+
should "setup the temp dir then export" do
|
11
|
+
exec_seq = sequence('execute')
|
12
|
+
@action.expects(:setup_temp_dir).once.in_sequence(exec_seq)
|
13
|
+
@action.expects(:export).once.in_sequence(exec_seq)
|
14
|
+
@action.execute!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "setting up the temporary directory" do
|
19
|
+
setup do
|
20
|
+
@time_now = Time.now.to_i.to_s
|
21
|
+
Time.stubs(:now).returns(@time_now)
|
22
|
+
|
23
|
+
@tmp_path = "foo"
|
24
|
+
Vagrant::Env.stubs(:tmp_path).returns(@tmp_path)
|
25
|
+
|
26
|
+
@temp_dir = File.join(Vagrant::Env.tmp_path, @time_now)
|
27
|
+
FileUtils.stubs(:mkpath)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "create the temporary directory using the current time" do
|
31
|
+
FileUtils.expects(:mkpath).with(@temp_dir).once
|
32
|
+
@action.setup_temp_dir
|
33
|
+
end
|
34
|
+
|
35
|
+
should "set the temporary directory to the temp_dir variable" do
|
36
|
+
@action.setup_temp_dir
|
37
|
+
assert_equal @temp_dir, @action.temp_dir
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "path to OVF file" do
|
42
|
+
setup do
|
43
|
+
@temp_dir = "foo"
|
44
|
+
@action.stubs(:temp_dir).returns(@temp_dir)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "be the temporary directory joined with the OVF filename" do
|
48
|
+
assert_equal File.join(@temp_dir, Vagrant.config.vm.box_ovf), @action.ovf_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "exporting" do
|
53
|
+
setup do
|
54
|
+
@ovf_path = mock("ovf_path")
|
55
|
+
@action.stubs(:ovf_path).returns(@ovf_path)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "call export on the runner with the ovf path" do
|
59
|
+
@vm.expects(:export).with(@ovf_path, {}, true).once
|
60
|
+
@action.export
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "cleanup" do
|
65
|
+
setup do
|
66
|
+
@temp_dir = "foo"
|
67
|
+
@action.stubs(:temp_dir).returns(@temp_dir)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "remove the temporary directory" do
|
71
|
+
FileUtils.expects(:rm_r).with(@temp_dir).once
|
72
|
+
@action.cleanup
|
73
|
+
end
|
74
|
+
|
75
|
+
should "not remove a directory if temp_dir is nil" do
|
76
|
+
FileUtils.expects(:rm_r).never
|
77
|
+
@action.stubs(:temp_dir).returns(nil)
|
78
|
+
@action.cleanup
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "rescue" do
|
83
|
+
should "call cleanup method" do
|
84
|
+
@action.expects(:cleanup).once
|
85
|
+
@action.rescue(nil)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ForwardPortsActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::ForwardPorts)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "execution" do
|
10
|
+
should "clear all previous ports and forward new ports" do
|
11
|
+
exec_seq = sequence("exec_seq")
|
12
|
+
@action.expects(:clear).once.in_sequence(exec_seq)
|
13
|
+
@action.expects(:forward_ports).once.in_sequence(exec_seq)
|
14
|
+
@action.execute!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "forwarding ports" do
|
19
|
+
should "create a port forwarding for the VM" do
|
20
|
+
forwarded_ports = mock("forwarded_ports")
|
21
|
+
|
22
|
+
Vagrant.config.vm.forwarded_ports.each do |name, opts|
|
23
|
+
forwarded_ports.expects(:<<).with do |port|
|
24
|
+
assert_equal name, port.name
|
25
|
+
assert_equal opts[:hostport], port.hostport
|
26
|
+
assert_equal opts[:guestport], port.guestport
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
32
|
+
@vm.expects(:save).with(true).once
|
33
|
+
@action.forward_ports
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "clearing forwarded ports" do
|
38
|
+
should "call destroy on all forwarded ports" do
|
39
|
+
forwarded_ports = []
|
40
|
+
5.times do |i|
|
41
|
+
port = mock("port#{i}")
|
42
|
+
port.expects(:destroy).with(true).once
|
43
|
+
forwarded_ports << port
|
44
|
+
end
|
45
|
+
|
46
|
+
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
47
|
+
@action.clear
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class HaltActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Halt)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "executing" do
|
10
|
+
setup do
|
11
|
+
@vm.stubs(:running?).returns(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "force the VM to stop" do
|
15
|
+
@vm.expects(:stop).with(true).once
|
16
|
+
@action.execute!
|
17
|
+
end
|
18
|
+
|
19
|
+
should "raise an ActionException if VM is not running" do
|
20
|
+
@vm.stubs(:running?).returns(false)
|
21
|
+
@vm.expects(:stop).never
|
22
|
+
assert_raises(Vagrant::Actions::ActionException) {
|
23
|
+
@action.execute!
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ImportActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@mock_vm, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
|
6
|
+
|
7
|
+
@ovf_file = "foo"
|
8
|
+
@box = mock("box")
|
9
|
+
@box.stubs(:ovf_file).returns(@ovf_file)
|
10
|
+
Vagrant::Env.stubs(:box).returns(@box)
|
11
|
+
|
12
|
+
VirtualBox::VM.stubs(:import)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "run in a busy block" do
|
16
|
+
Vagrant::Busy.expects(:busy).once
|
17
|
+
@import.execute!
|
18
|
+
end
|
19
|
+
|
20
|
+
should "invoke an around callback around the import" do
|
21
|
+
@mock_vm.expects(:invoke_around_callback).with(:import).once
|
22
|
+
@import.execute!
|
23
|
+
end
|
24
|
+
|
25
|
+
should "call import on VirtualBox::VM with the proper base" do
|
26
|
+
VirtualBox::VM.expects(:import).once.with(@ovf_file)
|
27
|
+
@import.execute!
|
28
|
+
end
|
29
|
+
|
30
|
+
should "set the resulting VM as the VM of the Vagrant VM object" do
|
31
|
+
new_vm = mock("new_vm")
|
32
|
+
@mock_vm.expects(:vm=).with(new_vm).once
|
33
|
+
VirtualBox::VM.expects(:import).returns(new_vm)
|
34
|
+
@import.execute!
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class MoveHardDriveActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::MoveHardDrive)
|
6
|
+
@hd_location = "/foo"
|
7
|
+
mock_config do |config|
|
8
|
+
File.expects(:directory?).with(@hd_location).returns(true)
|
9
|
+
config.vm.hd_location = @hd_location
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
should "be able to identifiy a hard drive within the storage controllers" do
|
15
|
+
hd = mock('hd')
|
16
|
+
hd_image = mock('hd_image')
|
17
|
+
hd_image.expects(:is_a?).returns(true)
|
18
|
+
hd.expects(:image).returns(hd_image)
|
19
|
+
|
20
|
+
dvd = mock('dvd')
|
21
|
+
controller = mock('controller')
|
22
|
+
controller.expects(:devices).returns([hd, dvd])
|
23
|
+
|
24
|
+
@vm.expects(:storage_controllers).once.returns([controller])
|
25
|
+
assert_equal @action.find_hard_drive, hd
|
26
|
+
end
|
27
|
+
|
28
|
+
context "execution" do
|
29
|
+
should "error and exit if the vm is not powered off" do
|
30
|
+
@mock_vm.expects(:powered_off?).returns(false)
|
31
|
+
@action.expects(:error_and_exit).once
|
32
|
+
@action.execute!
|
33
|
+
end
|
34
|
+
|
35
|
+
should "move the hard drive if vm is powered off" do
|
36
|
+
@mock_vm.expects(:powered_off?).returns(true)
|
37
|
+
@action.expects(:error_and_exit).never
|
38
|
+
@action.expects(:destroy_drive_after).once
|
39
|
+
@action.execute!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "new image path" do
|
44
|
+
setup do
|
45
|
+
@hd = mock("hd")
|
46
|
+
@image = mock("image")
|
47
|
+
@filename = "foo"
|
48
|
+
@hd.stubs(:image).returns(@image)
|
49
|
+
@image.stubs(:filename).returns(@filename)
|
50
|
+
@action.stubs(:hard_drive).returns(@hd)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "be the configured hd location and the existing hard drive filename" do
|
54
|
+
joined = File.join(Vagrant.config.vm.hd_location, @filename)
|
55
|
+
assert_equal joined, @action.new_image_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "cloning and attaching new image" do
|
60
|
+
setup do
|
61
|
+
@hd = mock("hd")
|
62
|
+
@image = mock("image")
|
63
|
+
@hd.stubs(:image).returns(@image)
|
64
|
+
@action.stubs(:hard_drive).returns(@hd)
|
65
|
+
@new_image_path = "foo"
|
66
|
+
@action.stubs(:new_image_path).returns(@new_image_path)
|
67
|
+
end
|
68
|
+
|
69
|
+
should "clone to the new path" do
|
70
|
+
new_image = mock("new_image")
|
71
|
+
@image.expects(:clone).with(@new_image_path, Vagrant.config.vm.disk_image_format, true).returns(new_image).once
|
72
|
+
@hd.expects(:image=).with(new_image).once
|
73
|
+
@vm.expects(:save).once
|
74
|
+
@action.clone_and_attach
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "destroying the old image" do
|
79
|
+
setup do
|
80
|
+
@hd = mock("hd")
|
81
|
+
@action.stubs(:hard_drive).returns(@hd)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "yield the block, and destroy the old image after" do
|
85
|
+
image = mock("image")
|
86
|
+
image.stubs(:filename).returns("foo")
|
87
|
+
destroy_seq = sequence("destroy_seq")
|
88
|
+
@hd.expects(:image).returns(image).in_sequence(destroy_seq)
|
89
|
+
@hd.expects(:foo).once.in_sequence(destroy_seq)
|
90
|
+
image.expects(:destroy).with(true).once.in_sequence(destroy_seq)
|
91
|
+
|
92
|
+
@action.destroy_drive_after { @hd.foo }
|
93
|
+
end
|
94
|
+
|
95
|
+
# Ensures that the image is not destroyed in an "ensure" block
|
96
|
+
should "not destroy the image if an exception is raised" do
|
97
|
+
image = mock("image")
|
98
|
+
image.expects(:destroy).never
|
99
|
+
@hd.expects(:image).returns(image)
|
100
|
+
|
101
|
+
assert_raises(Exception) do
|
102
|
+
@action.destroy_drive_after do
|
103
|
+
raise Exception.new("FOO")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class PackageActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", [])
|
6
|
+
|
7
|
+
mock_config
|
8
|
+
end
|
9
|
+
|
10
|
+
context "initialization" do
|
11
|
+
def get_action(*args)
|
12
|
+
runner, vm, action = mock_action(Vagrant::Actions::VM::Package, *args)
|
13
|
+
return action
|
14
|
+
end
|
15
|
+
|
16
|
+
should "make out_path 'package' by default if nil is given" do
|
17
|
+
action = get_action(nil, [])
|
18
|
+
assert_equal "package", action.out_path
|
19
|
+
end
|
20
|
+
|
21
|
+
should "make include files an empty array by default" do
|
22
|
+
action = get_action("foo", nil)
|
23
|
+
assert action.include_files.is_a?(Array)
|
24
|
+
assert action.include_files.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "executing" do
|
29
|
+
setup do
|
30
|
+
@action.stubs(:compress)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "compress" do
|
34
|
+
package_seq = sequence("package_seq")
|
35
|
+
@action.expects(:compress).in_sequence(package_seq)
|
36
|
+
@action.execute!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "tar path" do
|
41
|
+
should "be the temporary directory with the name and extension attached" do
|
42
|
+
pwd = "foo"
|
43
|
+
FileUtils.stubs(:pwd).returns(pwd)
|
44
|
+
assert_equal File.join(pwd, "#{@action.out_path}#{Vagrant.config.package.extension}"), @action.tar_path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "temp path" do
|
49
|
+
setup do
|
50
|
+
@export = mock("export")
|
51
|
+
@action.expects(:export_action).returns(@export)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "use the export action's temp dir" do
|
55
|
+
path = mock("path")
|
56
|
+
@export.expects(:temp_dir).returns(path)
|
57
|
+
@action.temp_path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "compression" do
|
62
|
+
setup do
|
63
|
+
@tar_path = "foo"
|
64
|
+
@action.stubs(:tar_path).returns(@tar_path)
|
65
|
+
|
66
|
+
@temp_path = "foo"
|
67
|
+
@action.stubs(:temp_path).returns(@temp_path)
|
68
|
+
|
69
|
+
@pwd = "bar"
|
70
|
+
FileUtils.stubs(:pwd).returns(@pwd)
|
71
|
+
FileUtils.stubs(:cd)
|
72
|
+
|
73
|
+
@tar = mock("tar")
|
74
|
+
Tar.stubs(:open).yields(@tar)
|
75
|
+
end
|
76
|
+
|
77
|
+
should "open the tar file with the tar path properly" do
|
78
|
+
Tar.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU).once
|
79
|
+
@action.compress
|
80
|
+
end
|
81
|
+
|
82
|
+
#----------------------------------------------------------------
|
83
|
+
# Methods below this comment test the block yielded by Tar.open
|
84
|
+
#----------------------------------------------------------------
|
85
|
+
should "cd to the directory and append the directory" do
|
86
|
+
compress_seq = sequence("compress_seq")
|
87
|
+
FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
|
88
|
+
FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq)
|
89
|
+
@tar.expects(:append_tree).with(".").in_sequence(compress_seq)
|
90
|
+
FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq)
|
91
|
+
@action.compress
|
92
|
+
end
|
93
|
+
|
94
|
+
should "pop back to the current directory even if an exception is raised" do
|
95
|
+
cd_seq = sequence("cd_seq")
|
96
|
+
FileUtils.expects(:cd).with(@temp_path).raises(Exception).in_sequence(cd_seq)
|
97
|
+
FileUtils.expects(:cd).with(@pwd).in_sequence(cd_seq)
|
98
|
+
|
99
|
+
assert_raises(Exception) {
|
100
|
+
@action.compress
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
should "add included files when passed" do
|
105
|
+
include_files = ['foo', 'bar']
|
106
|
+
action = mock_action(Vagrant::Actions::VM::Package, "bing", include_files).last
|
107
|
+
action.stubs(:temp_path).returns("foo")
|
108
|
+
@tar.expects(:append_tree).with(".")
|
109
|
+
include_files.each { |f| @tar.expects(:append_file).with(f) }
|
110
|
+
action.compress
|
111
|
+
end
|
112
|
+
|
113
|
+
should "not add files when none are specified" do
|
114
|
+
@tar.expects(:append_tree).with(".")
|
115
|
+
@tar.expects(:append_file).never
|
116
|
+
@action.compress
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "preparing the action" do
|
121
|
+
context "checking include files" do
|
122
|
+
setup do
|
123
|
+
@include_files = ['fooiest', 'booiest']
|
124
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", @include_files)
|
125
|
+
@runner.stubs(:find_action).returns("foo")
|
126
|
+
end
|
127
|
+
|
128
|
+
should "check that all the include files exist" do
|
129
|
+
@include_files.each do |file|
|
130
|
+
File.expects(:exists?).with(file).returns(true)
|
131
|
+
end
|
132
|
+
@action.prepare
|
133
|
+
end
|
134
|
+
|
135
|
+
should "raise an exception when an include file does not exist" do
|
136
|
+
File.expects(:exists?).once.returns(false)
|
137
|
+
assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "loading export reference" do
|
142
|
+
should "find and store a reference to the export action" do
|
143
|
+
@export = mock("export")
|
144
|
+
@runner.expects(:find_action).with(Vagrant::Actions::VM::Export).once.returns(@export)
|
145
|
+
@action.prepare
|
146
|
+
assert @export.equal?(@action.export_action)
|
147
|
+
end
|
148
|
+
|
149
|
+
should "raise an exception if the export action couldn't be found" do
|
150
|
+
@runner.expects(:find_action).with(Vagrant::Actions::VM::Export).once.returns(nil)
|
151
|
+
assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|