vagrantup 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/CHANGELOG.md +48 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +49 -0
  6. data/README.md +2 -2
  7. data/Rakefile +22 -0
  8. data/bin/.gitignore +0 -0
  9. data/lib/vagrant/provisioners/chef_solo.rb +1 -1
  10. data/lib/vagrant/util/template_renderer.rb +2 -2
  11. data/lib/vagrant/version.rb +1 -1
  12. data/templates/Vagrantfile.erb +1 -1
  13. data/templates/nfs/exports.erb +4 -2
  14. data/test/test_helper.rb +128 -0
  15. data/test/vagrant/action/box/destroy_test.rb +30 -0
  16. data/test/vagrant/action/box/download_test.rb +141 -0
  17. data/test/vagrant/action/box/package_test.rb +25 -0
  18. data/test/vagrant/action/box/unpackage_test.rb +103 -0
  19. data/test/vagrant/action/box/verify_test.rb +39 -0
  20. data/test/vagrant/action/builder_test.rb +218 -0
  21. data/test/vagrant/action/env/error_halt_test.rb +21 -0
  22. data/test/vagrant/action/env/set_test.rb +24 -0
  23. data/test/vagrant/action/environment_test.rb +45 -0
  24. data/test/vagrant/action/exception_catcher_test.rb +30 -0
  25. data/test/vagrant/action/general/package_test.rb +254 -0
  26. data/test/vagrant/action/vm/boot_test.rb +83 -0
  27. data/test/vagrant/action/vm/check_box_test.rb +48 -0
  28. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  29. data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
  30. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  31. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  32. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  33. data/test/vagrant/action/vm/customize_test.rb +29 -0
  34. data/test/vagrant/action/vm/destroy_test.rb +26 -0
  35. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
  36. data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
  37. data/test/vagrant/action/vm/discard_state_test.rb +36 -0
  38. data/test/vagrant/action/vm/export_test.rb +135 -0
  39. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  40. data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
  41. data/test/vagrant/action/vm/halt_test.rb +69 -0
  42. data/test/vagrant/action/vm/import_test.rb +50 -0
  43. data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
  44. data/test/vagrant/action/vm/network_test.rb +246 -0
  45. data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
  46. data/test/vagrant/action/vm/nfs_test.rb +269 -0
  47. data/test/vagrant/action/vm/package_test.rb +25 -0
  48. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  49. data/test/vagrant/action/vm/persist_test.rb +50 -0
  50. data/test/vagrant/action/vm/provision_test.rb +134 -0
  51. data/test/vagrant/action/vm/resume_test.rb +35 -0
  52. data/test/vagrant/action/vm/share_folders_test.rb +215 -0
  53. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  54. data/test/vagrant/action_test.rb +111 -0
  55. data/test/vagrant/active_list_test.rb +173 -0
  56. data/test/vagrant/box_test.rb +166 -0
  57. data/test/vagrant/command_test.rb +53 -0
  58. data/test/vagrant/commands/base_test.rb +139 -0
  59. data/test/vagrant/commands/box/add_test.rb +34 -0
  60. data/test/vagrant/commands/box/list_test.rb +32 -0
  61. data/test/vagrant/commands/box/remove_test.rb +41 -0
  62. data/test/vagrant/commands/box/repackage_test.rb +52 -0
  63. data/test/vagrant/commands/destroy_test.rb +44 -0
  64. data/test/vagrant/commands/halt_test.rb +50 -0
  65. data/test/vagrant/commands/init_test.rb +71 -0
  66. data/test/vagrant/commands/package_test.rb +97 -0
  67. data/test/vagrant/commands/provision_test.rb +60 -0
  68. data/test/vagrant/commands/reload_test.rb +47 -0
  69. data/test/vagrant/commands/resume_test.rb +44 -0
  70. data/test/vagrant/commands/ssh_config_test.rb +77 -0
  71. data/test/vagrant/commands/ssh_test.rb +129 -0
  72. data/test/vagrant/commands/status_test.rb +40 -0
  73. data/test/vagrant/commands/suspend_test.rb +44 -0
  74. data/test/vagrant/commands/up_test.rb +49 -0
  75. data/test/vagrant/config_test.rb +307 -0
  76. data/test/vagrant/downloaders/base_test.rb +28 -0
  77. data/test/vagrant/downloaders/file_test.rb +33 -0
  78. data/test/vagrant/downloaders/http_test.rb +70 -0
  79. data/test/vagrant/environment_test.rb +770 -0
  80. data/test/vagrant/hosts/base_test.rb +46 -0
  81. data/test/vagrant/hosts/bsd_test.rb +56 -0
  82. data/test/vagrant/hosts/linux_test.rb +56 -0
  83. data/test/vagrant/provisioners/base_test.rb +36 -0
  84. data/test/vagrant/provisioners/chef_server_test.rb +182 -0
  85. data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
  86. data/test/vagrant/provisioners/chef_test.rb +178 -0
  87. data/test/vagrant/ssh_session_test.rb +46 -0
  88. data/test/vagrant/ssh_test.rb +317 -0
  89. data/test/vagrant/systems/linux_test.rb +179 -0
  90. data/test/vagrant/util/busy_test.rb +106 -0
  91. data/test/vagrant/util/plain_logger_test.rb +17 -0
  92. data/test/vagrant/util/platform_test.rb +18 -0
  93. data/test/vagrant/util/resource_logger_test.rb +145 -0
  94. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  95. data/test/vagrant/util/template_renderer_test.rb +145 -0
  96. data/test/vagrant/util/translator_test.rb +61 -0
  97. data/test/vagrant/util_test.rb +27 -0
  98. data/test/vagrant/vm_test.rb +228 -0
  99. data/vagrant.gemspec +34 -0
  100. metadata +130 -9
@@ -0,0 +1,83 @@
1
+ require "test_helper"
2
+
3
+ class BootVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Boot
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @vm.stubs(:ssh).returns(mock("ssh"))
10
+ @env["vm"] = @vm
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+
15
+ @instance = @klass.new(@app, @env)
16
+ end
17
+
18
+ context "calling" do
19
+ should "do nothing if environment is erroneous" do
20
+ @env.error!(:foo)
21
+ @instance.expects(:boot).never
22
+ @app.expects(:call).never
23
+
24
+ @instance.call(@env)
25
+ end
26
+
27
+ should "run the proper methods on success" do
28
+ boot_seq = sequence("boot_seq")
29
+ @instance.expects(:boot).in_sequence(boot_seq)
30
+ @instance.expects(:wait_for_boot).returns(true).in_sequence(boot_seq)
31
+ @app.expects(:call).with(@env).once.in_sequence(boot_seq)
32
+ @instance.call(@env)
33
+ end
34
+
35
+ should "error and halt chain if boot failed" do
36
+ boot_seq = sequence("boot_seq")
37
+ @instance.expects(:boot).in_sequence(boot_seq)
38
+ @instance.expects(:wait_for_boot).returns(false).in_sequence(boot_seq)
39
+ @app.expects(:call).never
40
+ @instance.call(@env)
41
+ end
42
+
43
+ should "not continue chain if error occured" do
44
+ boot_seq = sequence("boot_seq")
45
+ @instance.expects(:boot).in_sequence(boot_seq)
46
+ @instance.expects(:wait_for_boot).returns(true).in_sequence(boot_seq).with() do
47
+ @env.error!(:interrupt)
48
+ true
49
+ end
50
+ @app.expects(:call).never
51
+ @instance.call(@env)
52
+ end
53
+ end
54
+
55
+ context "booting" do
56
+ should "start the VM in specified mode" do
57
+ mode = mock("boot_mode")
58
+ @env.env.config.vm.boot_mode = mode
59
+ @internal_vm.expects(:start).with(mode).once
60
+ @instance.boot
61
+ end
62
+ end
63
+
64
+ context "waiting for boot" do
65
+ should "repeatedly ping the SSH port and return false with no response" do
66
+ seq = sequence('pings')
67
+ @vm.ssh.expects(:up?).times(@env.env.config.ssh.max_tries.to_i - 1).returns(false).in_sequence(seq)
68
+ @vm.ssh.expects(:up?).once.returns(true).in_sequence(seq)
69
+ assert @instance.wait_for_boot
70
+ end
71
+
72
+ should "return right away if interrupted" do
73
+ @env.error!(:interrupt)
74
+ @vm.ssh.expects(:up?).times(1).returns(false)
75
+ assert @instance.wait_for_boot
76
+ end
77
+
78
+ should "ping the max number of times then just return" do
79
+ @vm.ssh.expects(:up?).times(@env.env.config.ssh.max_tries.to_i).returns(false)
80
+ assert !@instance.wait_for_boot
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class CheckBoxVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::CheckBox
6
+ @app, @env = mock_action_data
7
+ @instance = @klass.new(@app, @env)
8
+ end
9
+
10
+ context "calling" do
11
+ setup do
12
+ Vagrant::Box.stubs(:find)
13
+ end
14
+
15
+ should "return error if box not specified" do
16
+ @env.env.config.vm.box = nil
17
+
18
+ @app.expects(:call).never
19
+ @instance.call(@env)
20
+
21
+ assert @env.error?
22
+ assert_equal :box_not_specified, @env.error.first
23
+ end
24
+
25
+ should "error if box does not exist and URL not specified" do
26
+ @env.env.config.vm.box_url = nil
27
+ Vagrant::Box.expects(:find).with(@env.env, @env["config"].vm.box).returns(nil)
28
+
29
+ @app.expects(:call).never
30
+ @instance.call(@env)
31
+
32
+ assert @env.error?
33
+ assert_equal :box_specified_doesnt_exist, @env.error.first
34
+ end
35
+
36
+ should "attempt to download box and continue if URL specified" do
37
+ seq = sequence("seq")
38
+ @env.env.config.vm.box_url = "bar"
39
+ Vagrant::Box.expects(:find).returns(nil)
40
+ Vagrant::Box.expects(:add).with(@env.env, @env["config"].vm.box, @env["config"].vm.box_url).in_sequence(seq)
41
+ @env.env.expects(:load_box!).in_sequence(seq)
42
+ @app.expects(:call).with(@env).once.in_sequence(seq)
43
+
44
+ @instance.call(@env)
45
+ assert !@env.error?
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ class CheckGuestAdditionsVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::CheckGuestAdditions
6
+ end
7
+
8
+ # TODO: This isn't tested.
9
+ end
@@ -0,0 +1,82 @@
1
+ require "test_helper"
2
+
3
+ class CleanMachineFolderVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::CleanMachineFolder
6
+ @app, @env = mock_action_data
7
+
8
+ @instance = @klass.new(@app, @env)
9
+ end
10
+
11
+ context "calling" do
12
+ should "clean machine folder then continue chain" do
13
+ seq = sequence("seq")
14
+ @instance.expects(:clean_machine_folder).in_sequence(seq)
15
+ @app.expects(:call).with(@env).in_sequence(seq)
16
+ @instance.call(@env)
17
+ end
18
+ end
19
+
20
+ context "cleaning the folder" do
21
+ setup do
22
+ @machine_folder = "/foo/bar/baz"
23
+ @folder = File.join(@machine_folder, "*")
24
+ VirtualBox::Global.global.system_properties.stubs(:default_machine_folder).returns(@machine_folder)
25
+ File.stubs(:file?).returns(true)
26
+ end
27
+
28
+ should "ignore all non-directories" do
29
+ folders = %W[foo bar baz]
30
+ Dir.expects(:[]).with(@folder).returns(folders)
31
+ folders.each do |f|
32
+ File.expects(:directory?).with(f).returns(false)
33
+ end
34
+
35
+ FileUtils.expects(:rm_rf).never
36
+
37
+ @instance.clean_machine_folder
38
+ end
39
+
40
+ should "delete directories with only .xml-prev files" do
41
+ folders = {
42
+ "sfoo" => %W[foo bar baz.xml-prev],
43
+ "sbar" => %W[foo.xml-prev]
44
+ }
45
+
46
+ Dir.expects(:[]).with(@folder).returns(folders.keys)
47
+ folders.each do |folder, subfolders|
48
+ File.expects(:directory?).with(folder).returns(true)
49
+ Dir.expects(:[]).with("#{folder}/**/*").returns(subfolders)
50
+ end
51
+
52
+ FileUtils.expects(:rm_rf).never
53
+ FileUtils.expects(:rm_rf).with("sbar").once
54
+ @instance.clean_machine_folder
55
+ end
56
+
57
+ should "delete directories with only subdirectories" do
58
+ folders = {
59
+ "sfoo" => %W[foo bar],
60
+ "sbar" => %W[foo.xml-prev]
61
+ }
62
+
63
+ File.stubs(:file?).returns(false)
64
+ Dir.expects(:[]).with(@folder).returns(folders.keys)
65
+ folders.each do |folder, subfolders|
66
+ File.expects(:directory?).with(folder).returns(true)
67
+ Dir.expects(:[]).with("#{folder}/**/*").returns(subfolders)
68
+ end
69
+
70
+ FileUtils.expects(:rm_rf).never
71
+ FileUtils.expects(:rm_rf).with("sfoo").once
72
+ FileUtils.expects(:rm_rf).with("sbar").once
73
+
74
+ @instance.clean_machine_folder
75
+ end
76
+
77
+ should "do nothing if folder is < 10 characters" do
78
+ VirtualBox::Global.global.system_properties.stubs(:default_machine_folder).returns("foo")
79
+ Dir.expects(:[]).never
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,72 @@
1
+ require "test_helper"
2
+
3
+ class ClearForwardedPortsVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::ClearForwardedPorts
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @vm.stubs(:name).returns("foo")
10
+ @env["vm"] = @vm
11
+
12
+ @instance = @klass.new(@app, @env)
13
+ end
14
+
15
+ context "calling" do
16
+ should "call the proper methods and continue chain" do
17
+ seq = sequence('seq')
18
+ @instance.expects(:clear).in_sequence(seq)
19
+ @app.expects(:call).with(@env).in_sequence(seq)
20
+ @instance.call(@env)
21
+ end
22
+ end
23
+
24
+ context "clearing forwarded ports" do
25
+ setup do
26
+ @instance.stubs(:used_ports).returns([:a])
27
+ @instance.stubs(:clear_ports)
28
+ end
29
+
30
+ should "call destroy on all forwarded ports" do
31
+ @instance.expects(:clear_ports).once
32
+ @vm.expects(:reload!)
33
+ @instance.clear
34
+ end
35
+
36
+ should "do nothing if there are no forwarded ports" do
37
+ @instance.stubs(:used_ports).returns([])
38
+ @vm.expects(:reload!).never
39
+ @instance.clear
40
+ end
41
+ end
42
+
43
+ context "clearing ports" do
44
+ def mock_fp
45
+ fp = mock("fp")
46
+ fp.expects(:destroy).once
47
+ fp
48
+ end
49
+
50
+ setup do
51
+ VirtualBox.stubs(:version).returns("3.2.8")
52
+ @adapters = []
53
+ @internal_vm = mock("internal_vm")
54
+ @internal_vm.stubs(:network_adapters).returns(@adapters)
55
+ @vm.stubs(:vm).returns(@internal_vm)
56
+ end
57
+
58
+ def mock_adapter
59
+ na = mock("adapter")
60
+ engine = mock("engine")
61
+ engine.stubs(:forwarded_ports).returns([mock_fp])
62
+ na.stubs(:nat_driver).returns(engine)
63
+ na
64
+ end
65
+
66
+ should "destroy each forwarded port" do
67
+ @adapters << mock_adapter
68
+ @adapters << mock_adapter
69
+ @instance.clear_ports
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,22 @@
1
+ require "test_helper"
2
+
3
+ class ClearNFSExportsActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::ClearNFSExports
6
+ @app, @env = mock_action_data
7
+ @env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env))
8
+
9
+ @instance = @klass.new(@app, @env)
10
+ end
11
+
12
+ should "include the NFS helpers module" do
13
+ assert @klass.included_modules.include?(Vagrant::Action::VM::NFSHelpers)
14
+ end
15
+
16
+ should "clear NFS exports then continue chain" do
17
+ seq = sequence("seq")
18
+ @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
19
+ @app.expects(:call).with(@env).in_sequence(seq)
20
+ @instance.call(@env)
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require "test_helper"
2
+
3
+ class ClearSharedFoldersVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::ClearSharedFolders
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ should "call the proper methods in sequence" do
19
+ seq = sequence("seq")
20
+ @instance.expects(:clear_shared_folders).once.in_sequence(seq)
21
+ @app.expects(:call).with(@env).once
22
+ @instance.call(@env)
23
+ end
24
+ end
25
+
26
+ context "clearing shared folders" do
27
+ setup do
28
+ @shared_folder = mock("shared_folder")
29
+ @shared_folders = [@shared_folder]
30
+ @internal_vm.stubs(:shared_folders).returns(@shared_folders)
31
+ end
32
+
33
+ should "call destroy on each shared folder then reload" do
34
+ destroy_seq = sequence("destroy")
35
+ @shared_folders.each do |sf|
36
+ sf.expects(:destroy).once.in_sequence(destroy_seq)
37
+ end
38
+
39
+ @vm.expects(:reload!).once.in_sequence(destroy_seq)
40
+ @instance.clear_shared_folders
41
+ end
42
+
43
+ should "do nothing if no shared folders existed" do
44
+ @shared_folders.clear
45
+ @vm.expects(:reload!).never
46
+ @instance.clear_shared_folders
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class CustomizeVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Customize
6
+ @app, @env = mock_action_data
7
+ @instance = @klass.new(@app, @env)
8
+
9
+ @vm = mock("vm")
10
+ @env["vm"] = @vm
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+ end
15
+
16
+ should "not run anything if no customize blocks exist" do
17
+ @internal_vm.expects(:save).never
18
+ @app.expects(:call).with(@env).once
19
+ @instance.call(@env)
20
+ end
21
+
22
+ should "run the VM customization procs then save the VM" do
23
+ @env.env.config.vm.customize { |vm| }
24
+ @env.env.config.vm.expects(:run_procs!).with(@internal_vm)
25
+ @internal_vm.expects(:save).once
26
+ @app.expects(:call).with(@env).once
27
+ @instance.call(@env)
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+
3
+ class DestroyVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Destroy
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "destroying the VM" do
18
+ should "destroy VM and attached images" do
19
+ @internal_vm.expects(:destroy).with(:destroy_medium => :delete).once
20
+ @env["vm"].expects(:vm=).with(nil).once
21
+ @env.env.expects(:update_dotfile).once
22
+ @app.expects(:call).with(@env).once
23
+ @instance.call(@env)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class DestroyUnusedNetworkInterfacesVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::DestroyUnusedNetworkInterfaces
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ setup do
19
+ @network_adapters = []
20
+ @internal_vm.stubs(:network_adapters).returns(@network_adapters)
21
+ end
22
+
23
+ def stub_interface(length=5)
24
+ interface = mock("interface")
25
+ adapter = mock("adapter")
26
+ adapter.stubs(:host_interface_object).returns(interface)
27
+ interface.stubs(:attached_vms).returns(Array.new(length))
28
+
29
+ @network_adapters << adapter
30
+ interface
31
+ end
32
+
33
+ should "destroy only the unused network interfaces" do
34
+ stub_interface(5)
35
+ stub_interface(7)
36
+ results = [stub_interface(1), stub_interface(1)]
37
+
38
+ results.each do |result|
39
+ result.expects(:destroy).once
40
+ end
41
+
42
+ @app.expects(:call).with(@env).once
43
+ @instance.call(@env)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class DisableNetworksVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::DisableNetworks
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env.env.stubs(:vm).returns(@vm)
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+ @internal_vm.stubs(:network_adapters).returns([])
14
+
15
+ @instance = @klass.new(@app, @env)
16
+ end
17
+
18
+ def mock_adapter(type)
19
+ adapter = mock("adapter")
20
+ adapter.stubs(:attachment_type).returns(type)
21
+
22
+ if type == :host_only
23
+ adapter.expects(:enabled=).with(false)
24
+ adapter.expects(:save)
25
+ end
26
+
27
+ @internal_vm.network_adapters << adapter
28
+ end
29
+
30
+ should "remove all network adapters and continue chain" do
31
+ mock_adapter(:bridged)
32
+ mock_adapter(:host_only)
33
+ mock_adapter(:host_only)
34
+
35
+ @app.expects(:call).with(@env).once
36
+
37
+ @instance.call(@env)
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class DiscardStateVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::DiscardState
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ setup do
19
+ @internal_vm.stubs(:saved?).returns(false)
20
+ end
21
+
22
+ should "do nothing if not saved and continue chain" do
23
+ @internal_vm.expects(:saved?).returns(false)
24
+ @app.expects(:call).with(@env).once
25
+ @instance.call(@env)
26
+ end
27
+
28
+ should "discard state and continue chain" do
29
+ seq = sequence("sequence")
30
+ @internal_vm.expects(:saved?).returns(true).in_sequence(seq)
31
+ @internal_vm.expects(:discard_state).in_sequence(seq)
32
+ @app.expects(:call).with(@env).once.in_sequence(seq)
33
+ @instance.call(@env)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,135 @@
1
+ require "test_helper"
2
+
3
+ class ExportVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Export
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ setup do
19
+ @internal_vm.stubs(:powered_off?).returns(true)
20
+ end
21
+
22
+ should "call the proper methods then continue chain" do
23
+ seq = sequence("seq")
24
+ @instance.expects(:setup_temp_dir).in_sequence(seq)
25
+ @instance.expects(:export).in_sequence(seq)
26
+ @app.expects(:call).with(@env).in_sequence(seq)
27
+ @instance.expects(:cleanup).in_sequence(seq)
28
+
29
+ @instance.call(@env)
30
+ end
31
+
32
+ should "halt the chain if not powered off" do
33
+ @internal_vm.stubs(:powered_off?).returns(false)
34
+ @instance.expects(:setup_temp_dir).never
35
+ @instance.expects(:export).never
36
+ @app.expects(:call).with(@env).never
37
+ @instance.expects(:cleanup).never
38
+
39
+ @instance.call(@env)
40
+ assert @env.error?
41
+ assert_equal :vm_power_off_to_package, @env.error.first
42
+ end
43
+
44
+ should "halt the chain if env error" do
45
+ @internal_vm.stubs(:powered_off?).returns(true)
46
+ @instance.expects(:setup_temp_dir).never
47
+ @instance.expects(:export).never
48
+ @app.expects(:call).with(@env).never
49
+ @instance.expects(:cleanup).never
50
+
51
+ @env.error!(:interrupt)
52
+ @instance.call(@env)
53
+ end
54
+
55
+ should "halt the chain if env error when call is reached" do
56
+ @internal_vm.stubs(:powered_off?).returns(true)
57
+ @instance.expects(:setup_temp_dir).once
58
+ @instance.expects(:export).once.with() do
59
+ @env.error!(:interrupt)
60
+ true
61
+ end
62
+
63
+ @app.expects(:call).with(@env).never
64
+ @instance.expects(:cleanup).once
65
+
66
+ @instance.call(@env)
67
+ end
68
+ end
69
+
70
+ context "cleaning up" do
71
+ setup do
72
+ @temp_dir = "foo"
73
+ @instance.stubs(:temp_dir).returns(@temp_dir)
74
+ File.stubs(:exist?).returns(true)
75
+ end
76
+
77
+ should "delete the temporary file if it exists" do
78
+ File.expects(:unlink).with(@temp_dir).once
79
+ @instance.cleanup
80
+ end
81
+
82
+ should "not delete anything if it doesn't exist" do
83
+ File.stubs(:exist?).returns(false)
84
+ File.expects(:unlink).never
85
+ @instance.cleanup
86
+ end
87
+ end
88
+
89
+ context "setting up the temporary directory" do
90
+ setup do
91
+ @time_now = Time.now.to_i.to_s
92
+ Time.stubs(:now).returns(@time_now)
93
+
94
+ @tmp_path = "foo"
95
+ @env.env.stubs(:tmp_path).returns(@tmp_path)
96
+
97
+ @temp_dir = File.join(@env.env.tmp_path, @time_now)
98
+ FileUtils.stubs(:mkpath)
99
+ end
100
+
101
+ should "create the temporary directory using the current time" do
102
+ FileUtils.expects(:mkpath).with(@temp_dir).once
103
+ @instance.setup_temp_dir
104
+ end
105
+
106
+ should "set to the environment" do
107
+ @instance.setup_temp_dir
108
+ assert_equal @temp_dir, @env["export.temp_dir"]
109
+ assert_equal @temp_dir, @instance.temp_dir
110
+ end
111
+ end
112
+
113
+ context "exporting" do
114
+ setup do
115
+ @ovf_path = mock("ovf_path")
116
+ @instance.stubs(:ovf_path).returns(@ovf_path)
117
+ end
118
+
119
+ should "call export on the runner with the ovf path" do
120
+ @internal_vm.expects(:export).with(@ovf_path).once
121
+ @instance.export
122
+ end
123
+ end
124
+
125
+ context "path to OVF file" do
126
+ setup do
127
+ @temp_dir = "foo"
128
+ @env["export.temp_dir"] = @temp_dir
129
+ end
130
+
131
+ should "be the temporary directory joined with the OVF filename" do
132
+ assert_equal File.join(@temp_dir, @env.env.config.vm.box_ovf), @instance.ovf_path
133
+ end
134
+ end
135
+ end