vagrant 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.md +48 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +49 -0
  5. data/README.md +2 -2
  6. data/Rakefile +22 -0
  7. data/bin/.gitignore +0 -0
  8. data/lib/vagrant/provisioners/chef_solo.rb +1 -1
  9. data/lib/vagrant/util/template_renderer.rb +2 -2
  10. data/lib/vagrant/version.rb +1 -1
  11. data/templates/Vagrantfile.erb +1 -1
  12. data/templates/nfs/exports.erb +4 -2
  13. data/test/test_helper.rb +128 -0
  14. data/test/vagrant/action/box/destroy_test.rb +30 -0
  15. data/test/vagrant/action/box/download_test.rb +141 -0
  16. data/test/vagrant/action/box/package_test.rb +25 -0
  17. data/test/vagrant/action/box/unpackage_test.rb +103 -0
  18. data/test/vagrant/action/box/verify_test.rb +39 -0
  19. data/test/vagrant/action/builder_test.rb +218 -0
  20. data/test/vagrant/action/env/error_halt_test.rb +21 -0
  21. data/test/vagrant/action/env/set_test.rb +24 -0
  22. data/test/vagrant/action/environment_test.rb +45 -0
  23. data/test/vagrant/action/exception_catcher_test.rb +30 -0
  24. data/test/vagrant/action/general/package_test.rb +254 -0
  25. data/test/vagrant/action/vm/boot_test.rb +83 -0
  26. data/test/vagrant/action/vm/check_box_test.rb +48 -0
  27. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  28. data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
  29. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  30. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  31. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  32. data/test/vagrant/action/vm/customize_test.rb +29 -0
  33. data/test/vagrant/action/vm/destroy_test.rb +26 -0
  34. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
  35. data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
  36. data/test/vagrant/action/vm/discard_state_test.rb +36 -0
  37. data/test/vagrant/action/vm/export_test.rb +135 -0
  38. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  39. data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
  40. data/test/vagrant/action/vm/halt_test.rb +69 -0
  41. data/test/vagrant/action/vm/import_test.rb +50 -0
  42. data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
  43. data/test/vagrant/action/vm/network_test.rb +246 -0
  44. data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
  45. data/test/vagrant/action/vm/nfs_test.rb +269 -0
  46. data/test/vagrant/action/vm/package_test.rb +25 -0
  47. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  48. data/test/vagrant/action/vm/persist_test.rb +50 -0
  49. data/test/vagrant/action/vm/provision_test.rb +134 -0
  50. data/test/vagrant/action/vm/resume_test.rb +35 -0
  51. data/test/vagrant/action/vm/share_folders_test.rb +215 -0
  52. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  53. data/test/vagrant/action_test.rb +111 -0
  54. data/test/vagrant/active_list_test.rb +173 -0
  55. data/test/vagrant/box_test.rb +166 -0
  56. data/test/vagrant/command_test.rb +53 -0
  57. data/test/vagrant/commands/base_test.rb +139 -0
  58. data/test/vagrant/commands/box/add_test.rb +34 -0
  59. data/test/vagrant/commands/box/list_test.rb +32 -0
  60. data/test/vagrant/commands/box/remove_test.rb +41 -0
  61. data/test/vagrant/commands/box/repackage_test.rb +52 -0
  62. data/test/vagrant/commands/destroy_test.rb +44 -0
  63. data/test/vagrant/commands/halt_test.rb +50 -0
  64. data/test/vagrant/commands/init_test.rb +71 -0
  65. data/test/vagrant/commands/package_test.rb +97 -0
  66. data/test/vagrant/commands/provision_test.rb +60 -0
  67. data/test/vagrant/commands/reload_test.rb +47 -0
  68. data/test/vagrant/commands/resume_test.rb +44 -0
  69. data/test/vagrant/commands/ssh_config_test.rb +77 -0
  70. data/test/vagrant/commands/ssh_test.rb +129 -0
  71. data/test/vagrant/commands/status_test.rb +40 -0
  72. data/test/vagrant/commands/suspend_test.rb +44 -0
  73. data/test/vagrant/commands/up_test.rb +49 -0
  74. data/test/vagrant/config_test.rb +307 -0
  75. data/test/vagrant/downloaders/base_test.rb +28 -0
  76. data/test/vagrant/downloaders/file_test.rb +33 -0
  77. data/test/vagrant/downloaders/http_test.rb +70 -0
  78. data/test/vagrant/environment_test.rb +770 -0
  79. data/test/vagrant/hosts/base_test.rb +46 -0
  80. data/test/vagrant/hosts/bsd_test.rb +56 -0
  81. data/test/vagrant/hosts/linux_test.rb +56 -0
  82. data/test/vagrant/provisioners/base_test.rb +36 -0
  83. data/test/vagrant/provisioners/chef_server_test.rb +182 -0
  84. data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
  85. data/test/vagrant/provisioners/chef_test.rb +178 -0
  86. data/test/vagrant/ssh_session_test.rb +46 -0
  87. data/test/vagrant/ssh_test.rb +317 -0
  88. data/test/vagrant/systems/linux_test.rb +179 -0
  89. data/test/vagrant/util/busy_test.rb +106 -0
  90. data/test/vagrant/util/plain_logger_test.rb +17 -0
  91. data/test/vagrant/util/platform_test.rb +18 -0
  92. data/test/vagrant/util/resource_logger_test.rb +145 -0
  93. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  94. data/test/vagrant/util/template_renderer_test.rb +145 -0
  95. data/test/vagrant/util/translator_test.rb +61 -0
  96. data/test/vagrant/util_test.rb +27 -0
  97. data/test/vagrant/vm_test.rb +228 -0
  98. data/vagrant.gemspec +34 -0
  99. metadata +158 -43
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class NFSHelpersVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Class.new
6
+ @klass.send(:include, Vagrant::Action::VM::NFSHelpers)
7
+ @app, @env = mock_action_data
8
+
9
+ @instance = @klass.new
10
+ end
11
+
12
+ should "clear NFS exports for the environment if the host exists" do
13
+ @host = mock("host")
14
+ @env.env.stubs(:host).returns(@host)
15
+ @host.expects(:nfs_cleanup).once
16
+
17
+ @instance.clear_nfs_exports(@env)
18
+ end
19
+
20
+ should "not do anything if host is nil" do
21
+ assert_nothing_raised { @instance.clear_nfs_exports(@env) }
22
+ end
23
+ end
@@ -0,0 +1,269 @@
1
+ require "test_helper"
2
+
3
+ class NFSVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::NFS
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @vm.stubs(:system).returns(mock("system"))
10
+ @env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env))
11
+ @env.env.config.vm.network("192.168.55.1")
12
+ @env["vm"] = @vm
13
+
14
+ @internal_vm = mock("internal")
15
+ @vm.stubs(:vm).returns(@internal_vm)
16
+ end
17
+
18
+ context "initializing" do
19
+ should "not call verify settings if NFS is not enabled" do
20
+ @klass.any_instance.expects(:verify_settings).never
21
+ @klass.new(@app, @env)
22
+ end
23
+
24
+ should "call verify settings if NFS is enabled" do
25
+ @env.env.config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
26
+ @klass.any_instance.expects(:verify_settings).once
27
+ @klass.new(@app, @env)
28
+ end
29
+ end
30
+
31
+ context "with an instance" do
32
+ setup do
33
+ @instance = @klass.new(@app, @env)
34
+ end
35
+
36
+ context "calling" do
37
+ setup do
38
+ @instance.stubs(:folders).returns([:a])
39
+
40
+ [:clear_nfs_exports, :extract_folders, :prepare_folders, :export_folders, :mount_folders].each do |meth|
41
+ @instance.stubs(meth)
42
+ end
43
+ end
44
+
45
+ should "call the proper sequence and succeed" do
46
+ seq = sequence('seq')
47
+ @instance.expects(:extract_folders).in_sequence(seq)
48
+ @instance.expects(:prepare_folders).in_sequence(seq)
49
+ @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
50
+ @instance.expects(:export_folders).in_sequence(seq)
51
+ @app.expects(:call).with(@env).in_sequence(seq)
52
+ @instance.expects(:mount_folders).in_sequence(seq)
53
+ @instance.call(@env)
54
+ end
55
+
56
+ should "not export folders if folders is empty" do
57
+ @instance.stubs(:folders).returns([])
58
+
59
+ seq = sequence('seq')
60
+ @instance.expects(:extract_folders).in_sequence(seq)
61
+ @instance.expects(:prepare_folders).never
62
+ @instance.expects(:export_folders).never
63
+ @instance.expects(:clear_nfs_exports).never
64
+ @app.expects(:call).with(@env).in_sequence(seq)
65
+ @instance.expects(:mount_folders).never
66
+ @instance.call(@env)
67
+ end
68
+
69
+ should "halt chain if environment error occured" do
70
+ @env.error!(:foo)
71
+
72
+ seq = sequence('seq')
73
+ @instance.expects(:extract_folders).in_sequence(seq)
74
+ @instance.expects(:prepare_folders).in_sequence(seq)
75
+ @instance.expects(:clear_nfs_exports).in_sequence(seq)
76
+ @instance.expects(:export_folders).in_sequence(seq)
77
+ @app.expects(:call).never
78
+ @instance.call(@env)
79
+ end
80
+
81
+ should "not mount folders if an error occured" do
82
+ seq = sequence("seq")
83
+ @app.expects(:call).in_sequence(seq).with() do
84
+ # Use this mark the env as error
85
+ @env.error!(:foo)
86
+
87
+ true
88
+ end
89
+
90
+ @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
91
+
92
+ @instance.expects(:mount_folders).never
93
+ @instance.call(@env)
94
+ end
95
+ end
96
+
97
+ context "extracting folders" do
98
+ setup do
99
+ @env.env.config.vm.shared_folders.clear
100
+ @env.env.config.vm.share_folder("v-foo", "/foo", ".", :nfs => true)
101
+ @env.env.config.vm.share_folder("v-bar", "/bar", ".", :nfs => true)
102
+ end
103
+
104
+ should "extract the NFS enabled folders" do
105
+ @instance.extract_folders
106
+ assert_equal 2, @instance.folders.length
107
+ end
108
+
109
+ should "mark the folders disabled from the original config" do
110
+ @instance.extract_folders
111
+ %W[v-foo v-bar].each do |key|
112
+ assert @env["config"].vm.shared_folders[key][:disabled]
113
+ end
114
+ end
115
+
116
+ should "expand the hostpath relative to the env root" do
117
+ @instance.extract_folders
118
+ %W[v-foo v-bar].each do |key|
119
+ opts = @env["config"].vm.shared_folders[key]
120
+ assert_equal File.expand_path(opts[:hostpath], @env.env.root_path), @instance.folders[key][:hostpath]
121
+ end
122
+ end
123
+ end
124
+
125
+ context "preparing UID/GID" do
126
+ setup do
127
+ @stat = mock("stat")
128
+ File.stubs(:stat).returns(@stat)
129
+ end
130
+
131
+ should "return nil if the perm is not set" do
132
+ assert_nil @instance.prepare_permission(:uid, {:gid => 7})
133
+ end
134
+
135
+ should "return nil if the perm explicitly says nil" do
136
+ assert_nil @instance.prepare_permission(:uid, {:uid => nil})
137
+ end
138
+
139
+ should "return the set value if it is set" do
140
+ assert_equal 7, @instance.prepare_permission(:gid, {:map_gid => 7})
141
+ end
142
+
143
+ should "return the global config value if set and not explicitly set on folder" do
144
+ @env.env.config.nfs.map_gid = 12
145
+ assert_equal 12, @instance.prepare_permission(:gid, {})
146
+ end
147
+
148
+ should "return the stat result of the hostpath if :auto" do
149
+ opts = { :hostpath => "foo", :map_uid => :auto }
150
+ File.expects(:stat).with(opts[:hostpath]).returns(@stat)
151
+ @stat.stubs(:uid).returns(24)
152
+
153
+ assert_equal 24, @instance.prepare_permission(:uid, opts)
154
+ end
155
+ end
156
+
157
+ context "exporting folders" do
158
+ setup do
159
+ @instance.stubs(:folders).returns({})
160
+ @instance.stubs(:guest_ip).returns("192.168.33.10")
161
+ end
162
+
163
+ should "call nfs_export on the host" do
164
+ @env["host"].expects(:nfs_export).with(@instance.guest_ip, @instance.folders)
165
+ @instance.export_folders
166
+ end
167
+
168
+ should "error the environment if exception is raised" do
169
+ @env["host"].expects(:nfs_export).raises(Vagrant::Action::ActionException.new(:foo))
170
+ @instance.export_folders
171
+ assert @env.error?
172
+ assert_equal :foo, @env.error.first
173
+ end
174
+ end
175
+
176
+ context "mounting folders" do
177
+ setup do
178
+ @instance.stubs(:host_ip).returns("foo")
179
+ @instance.stubs(:folders).returns(["bar"])
180
+ end
181
+
182
+ should "mount the folders on the system" do
183
+ @vm.system.expects(:mount_nfs).with(@instance.host_ip, @instance.folders)
184
+ @instance.mount_folders
185
+ end
186
+ end
187
+
188
+ context "getting the host IP" do
189
+ setup do
190
+ @network_adapters = []
191
+ @internal_vm.stubs(:network_adapters).returns(@network_adapters)
192
+ end
193
+
194
+ def stub_interface(ip)
195
+ interface = mock("interface")
196
+ adapter = mock("adapter")
197
+ adapter.stubs(:host_interface_object).returns(interface)
198
+ interface.stubs(:ip_address).returns(ip)
199
+
200
+ @network_adapters << adapter
201
+ interface
202
+ end
203
+
204
+ should "return the IP of the first interface" do
205
+ ip = "192.168.1.1"
206
+ stub_interface(ip)
207
+
208
+ assert_equal ip, @instance.host_ip
209
+ end
210
+
211
+ should "return nil if no IP is found" do
212
+ assert_nil @instance.host_ip
213
+ end
214
+ end
215
+
216
+ context "getting the guest IP" do
217
+ should "return the first networked IP" do
218
+ ip = "192.168.33.10"
219
+ @env.env.config.vm.network(ip, :adapter => 1)
220
+ @env.env.config.vm.network("192.168.66.10", :adapter => 2)
221
+ assert_equal ip, @instance.guest_ip
222
+ end
223
+ end
224
+
225
+ context "nfs enabled" do
226
+ should "return false if no folders are marked for NFS" do
227
+ assert !@instance.nfs_enabled?
228
+ end
229
+
230
+ should "return true if a shared folder is marked for NFS" do
231
+ @env.env.config.vm.share_folder("v-foo", "/foo", "/bar", :nfs => true)
232
+ assert @instance.nfs_enabled?
233
+ end
234
+ end
235
+
236
+ context "verifying settings" do
237
+ setup do
238
+ @env.env.host.stubs(:nfs?).returns(true)
239
+ end
240
+
241
+ should "error environment if host is nil" do
242
+ @env.env.stubs(:host).returns(nil)
243
+ @instance.verify_settings
244
+ assert @env.error?
245
+ assert_equal :nfs_host_required, @env.error.first
246
+ end
247
+
248
+ should "error environment if host does not support NFS" do
249
+ @env.env.host.stubs(:nfs?).returns(false)
250
+ @instance.verify_settings
251
+ assert @env.error?
252
+ assert_equal :nfs_not_supported, @env.error.first
253
+ end
254
+
255
+ should "error environment if host only networking is not enabled" do
256
+ @env.env.config.vm.network_options.clear
257
+ @instance.verify_settings
258
+ assert @env.error?
259
+ assert_equal :nfs_no_host_network, @env.error.first
260
+ end
261
+
262
+ should "be fine if everything passes" do
263
+ @env.env.host.stubs(:nfs?).returns(true)
264
+ @instance.verify_settings
265
+ assert !@env.error?
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class PackageVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Package
6
+ @app, @env = mock_action_data
7
+ @env["export.temp_dir"] = "foo"
8
+
9
+ @instance = @klass.new(@app, @env)
10
+ end
11
+
12
+ should "be a subclass of general packaging middleware" do
13
+ assert @instance.is_a?(Vagrant::Action::General::Package)
14
+ end
15
+
16
+ should "set the package directory then call parent" do
17
+ @instance.expects(:general_call).once.with() do |env|
18
+ assert env["package.directory"]
19
+ assert_equal env["package.directory"], env["export.temp_dir"]
20
+ true
21
+ end
22
+
23
+ @instance.call(@env)
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class PackageVagrantfileVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::PackageVagrantfile
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+ @env["export.temp_dir"] = "foo"
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ should "create the vagrantfile then continue chain" do
19
+ seq = sequence("sequence")
20
+ @instance.expects(:create_vagrantfile).in_sequence(seq)
21
+ @app.expects(:call).with(@env).in_sequence(seq)
22
+
23
+ @instance.call(@env)
24
+ end
25
+ end
26
+
27
+ context "creating vagrantfile" do
28
+ setup do
29
+ @network_adapter = mock("nic")
30
+ @network_adapter.stubs(:mac_address).returns("mac_address")
31
+ @internal_vm.stubs(:network_adapters).returns([@network_adapter])
32
+ end
33
+
34
+ should "write the rendered vagrantfile to temp_path Vagrantfile" do
35
+ f = mock("file")
36
+ rendered = mock("rendered")
37
+ File.expects(:open).with(File.join(@env["export.temp_dir"], "Vagrantfile"), "w").yields(f)
38
+ Vagrant::Util::TemplateRenderer.expects(:render).returns(rendered).with("package_Vagrantfile", {
39
+ :base_mac => @internal_vm.network_adapters.first.mac_address
40
+ })
41
+ f.expects(:write).with(rendered)
42
+
43
+ @instance.create_vagrantfile
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class PersistVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Persist
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @vm.stubs(:uuid).returns("123")
10
+ @env["vm"] = @vm
11
+ end
12
+
13
+ context "initializing" do
14
+ setup do
15
+ File.stubs(:file?).returns(true)
16
+ File.stubs(:exist?).returns(true)
17
+ @dotfile_path = "foo"
18
+ @env.env.stubs(:dotfile_path).returns(@dotfile_path)
19
+ end
20
+
21
+ should "error environment if dotfile exists but is not a file" do
22
+ File.expects(:file?).with(@env.env.dotfile_path).returns(false)
23
+ @klass.new(@app, @env)
24
+ assert @env.error?
25
+ assert_equal :dotfile_error, @env.error.first
26
+ end
27
+
28
+ should "initialize properly if dotfiles doesn't exist" do
29
+ File.expects(:exist?).with(@env.env.dotfile_path).returns(false)
30
+ @klass.new(@app, @env)
31
+ assert !@env.error?
32
+ end
33
+ end
34
+
35
+ context "with an instance" do
36
+ setup do
37
+ File.stubs(:file?).returns(true)
38
+ File.stubs(:exist?).returns(true)
39
+ @instance = @klass.new(@app, @env)
40
+ end
41
+
42
+ should "persist the dotfile then continue chain" do
43
+ update_seq = sequence("update_seq")
44
+ @env.env.expects(:update_dotfile).in_sequence(update_seq)
45
+ @app.expects(:call).with(@env).in_sequence(update_seq)
46
+
47
+ @instance.call(@env)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,134 @@
1
+ require "test_helper"
2
+
3
+ class ProvisionVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Provision
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @vm.stubs(:name).returns("foo")
10
+ @vm.stubs(:ssh).returns(mock("ssh"))
11
+ @vm.stubs(:system).returns(mock("system"))
12
+ @env["vm"] = @vm
13
+
14
+ @internal_vm = mock("internal")
15
+ @vm.stubs(:vm).returns(@internal_vm)
16
+ end
17
+
18
+ context "initializing" do
19
+ setup do
20
+ @klass.any_instance.stubs(:load_provisioner)
21
+ end
22
+
23
+ should "load provisioner if provisioning enabled" do
24
+ @env["config"].vm.provisioner = :chef_solo
25
+ @klass.any_instance.expects(:load_provisioner).once
26
+ @klass.new(@app, @env)
27
+ end
28
+
29
+ should "not load provisioner if disabled" do
30
+ @env["config"].vm.provisioner = nil
31
+ @klass.any_instance.expects(:load_provisioner).never
32
+ @klass.new(@app, @env)
33
+ end
34
+ end
35
+
36
+ context "with an instance" do
37
+ setup do
38
+ # Set provisioner to nil so the provisioner isn't loaded on init
39
+ @env["config"].vm.provisioner = nil
40
+ @instance = @klass.new(@app, @env)
41
+ end
42
+
43
+ context "loading a provisioner" do
44
+ context "with a Class provisioner" do
45
+ setup do
46
+ @prov = mock("instance")
47
+ @prov.stubs(:is_a?).with(Vagrant::Provisioners::Base).returns(true)
48
+ @prov.stubs(:prepare)
49
+ @klass = mock("klass")
50
+ @klass.stubs(:is_a?).with(Class).returns(true)
51
+ @klass.stubs(:new).with(@env).returns(@prov)
52
+
53
+ @env["config"].vm.provisioner = @klass
54
+ end
55
+
56
+ should "set the provisioner to an instantiation of the class" do
57
+ @klass.expects(:new).with(@env).once.returns(@prov)
58
+ assert_equal @prov, @instance.load_provisioner
59
+ end
60
+
61
+ should "call prepare on the instance" do
62
+ @prov.expects(:prepare).once
63
+ @instance.load_provisioner
64
+ end
65
+
66
+ should "error environment if the class is not a subclass of the provisioner base" do
67
+ @prov.expects(:is_a?).with(Vagrant::Provisioners::Base).returns(false)
68
+ @instance.load_provisioner
69
+ assert @env.error?
70
+ assert_equal :provisioner_invalid_class, @env.error.first
71
+ end
72
+ end
73
+
74
+ context "with a Symbol provisioner" do
75
+ def provisioner_expectation(symbol, provisioner)
76
+ @env[:config].vm.provisioner = symbol
77
+
78
+ instance = mock("instance")
79
+ instance.expects(:prepare).once
80
+ provisioner.expects(:new).with(@env).returns(instance)
81
+ assert_equal instance, @instance.load_provisioner
82
+ end
83
+
84
+ should "raise an ActionException if its an unknown symbol" do
85
+ @env["config"].vm.provisioner = :this_will_never_exist
86
+ @instance.load_provisioner
87
+ assert @env.error?
88
+ assert_equal :provisioner_unknown_type, @env.error.first
89
+ end
90
+
91
+ should "set :chef_solo to the ChefSolo provisioner" do
92
+ provisioner_expectation(:chef_solo, Vagrant::Provisioners::ChefSolo)
93
+ end
94
+
95
+ should "set :chef_server to the ChefServer provisioner" do
96
+ provisioner_expectation(:chef_server, Vagrant::Provisioners::ChefServer)
97
+ end
98
+ end
99
+ end
100
+
101
+ context "calling" do
102
+ setup do
103
+ Vagrant::Provisioners::ChefSolo.any_instance.stubs(:prepare)
104
+ @env["config"].vm.provisioner = :chef_solo
105
+ @prov = @instance.load_provisioner
106
+ end
107
+
108
+ should "provision and continue chain" do
109
+ seq = sequence("seq")
110
+ @app.expects(:call).with(@env).in_sequence(seq)
111
+ @prov.expects(:provision!).in_sequence(seq)
112
+
113
+ @instance.call(@env)
114
+ end
115
+
116
+ should "continue chain and not provision if not enabled" do
117
+ @env["config"].vm.provisioner = nil
118
+ @prov.expects(:provision!).never
119
+ @app.expects(:call).with(@env).once
120
+
121
+ @instance.call(@env)
122
+ end
123
+
124
+ should "not provision if erroneous environment" do
125
+ @env.error!(:foo)
126
+
127
+ @prov.expects(:provision!).never
128
+ @app.expects(:call).with(@env).once
129
+
130
+ @instance.call(@env)
131
+ end
132
+ end
133
+ end
134
+ end