bmabey-vagrant 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +12 -0
  2. data/Gemfile +17 -0
  3. data/LICENSE +21 -0
  4. data/README.md +53 -0
  5. data/Rakefile +41 -0
  6. data/VERSION +1 -0
  7. data/bin/.gitignore +0 -0
  8. data/bin/vagrant +15 -0
  9. data/bin/vagrant-box +34 -0
  10. data/bin/vagrant-down +27 -0
  11. data/bin/vagrant-halt +28 -0
  12. data/bin/vagrant-init +27 -0
  13. data/bin/vagrant-package +29 -0
  14. data/bin/vagrant-reload +29 -0
  15. data/bin/vagrant-resume +27 -0
  16. data/bin/vagrant-ssh +27 -0
  17. data/bin/vagrant-status +29 -0
  18. data/bin/vagrant-suspend +27 -0
  19. data/bin/vagrant-up +29 -0
  20. data/config/default.rb +26 -0
  21. data/keys/README.md +10 -0
  22. data/keys/vagrant +27 -0
  23. data/keys/vagrant.pub +1 -0
  24. data/lib/vagrant.rb +19 -0
  25. data/lib/vagrant/actions/base.rb +118 -0
  26. data/lib/vagrant/actions/box/add.rb +22 -0
  27. data/lib/vagrant/actions/box/destroy.rb +14 -0
  28. data/lib/vagrant/actions/box/download.rb +72 -0
  29. data/lib/vagrant/actions/box/unpackage.rb +43 -0
  30. data/lib/vagrant/actions/collection.rb +36 -0
  31. data/lib/vagrant/actions/runner.rb +132 -0
  32. data/lib/vagrant/actions/vm/boot.rb +47 -0
  33. data/lib/vagrant/actions/vm/customize.rb +17 -0
  34. data/lib/vagrant/actions/vm/destroy.rb +23 -0
  35. data/lib/vagrant/actions/vm/down.rb +12 -0
  36. data/lib/vagrant/actions/vm/export.rb +41 -0
  37. data/lib/vagrant/actions/vm/forward_ports.rb +46 -0
  38. data/lib/vagrant/actions/vm/halt.rb +14 -0
  39. data/lib/vagrant/actions/vm/import.rb +18 -0
  40. data/lib/vagrant/actions/vm/move_hard_drive.rb +51 -0
  41. data/lib/vagrant/actions/vm/package.rb +65 -0
  42. data/lib/vagrant/actions/vm/provision.rb +49 -0
  43. data/lib/vagrant/actions/vm/reload.rb +17 -0
  44. data/lib/vagrant/actions/vm/resume.rb +16 -0
  45. data/lib/vagrant/actions/vm/shared_folders.rb +81 -0
  46. data/lib/vagrant/actions/vm/start.rb +18 -0
  47. data/lib/vagrant/actions/vm/suspend.rb +16 -0
  48. data/lib/vagrant/actions/vm/up.rb +40 -0
  49. data/lib/vagrant/active_list.rb +73 -0
  50. data/lib/vagrant/box.rb +152 -0
  51. data/lib/vagrant/busy.rb +73 -0
  52. data/lib/vagrant/commands.rb +219 -0
  53. data/lib/vagrant/config.rb +183 -0
  54. data/lib/vagrant/downloaders/base.rb +16 -0
  55. data/lib/vagrant/downloaders/file.rb +17 -0
  56. data/lib/vagrant/downloaders/http.rb +47 -0
  57. data/lib/vagrant/environment.rb +263 -0
  58. data/lib/vagrant/provisioners/base.rb +29 -0
  59. data/lib/vagrant/provisioners/chef.rb +103 -0
  60. data/lib/vagrant/provisioners/chef_server.rb +84 -0
  61. data/lib/vagrant/provisioners/chef_solo.rb +97 -0
  62. data/lib/vagrant/ssh.rb +104 -0
  63. data/lib/vagrant/util.rb +51 -0
  64. data/lib/vagrant/util/errors.rb +36 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +61 -0
  68. data/templates/Vagrantfile.erb +8 -0
  69. data/templates/errors.yml +117 -0
  70. data/test/test_helper.rb +163 -0
  71. data/test/vagrant/actions/base_test.rb +32 -0
  72. data/test/vagrant/actions/box/add_test.rb +37 -0
  73. data/test/vagrant/actions/box/destroy_test.rb +18 -0
  74. data/test/vagrant/actions/box/download_test.rb +131 -0
  75. data/test/vagrant/actions/box/unpackage_test.rb +100 -0
  76. data/test/vagrant/actions/collection_test.rb +110 -0
  77. data/test/vagrant/actions/runner_test.rb +265 -0
  78. data/test/vagrant/actions/vm/boot_test.rb +55 -0
  79. data/test/vagrant/actions/vm/customize_test.rb +16 -0
  80. data/test/vagrant/actions/vm/destroy_test.rb +36 -0
  81. data/test/vagrant/actions/vm/down_test.rb +32 -0
  82. data/test/vagrant/actions/vm/export_test.rb +88 -0
  83. data/test/vagrant/actions/vm/forward_ports_test.rb +104 -0
  84. data/test/vagrant/actions/vm/halt_test.rb +27 -0
  85. data/test/vagrant/actions/vm/import_test.rb +43 -0
  86. data/test/vagrant/actions/vm/move_hard_drive_test.rb +108 -0
  87. data/test/vagrant/actions/vm/package_test.rb +181 -0
  88. data/test/vagrant/actions/vm/provision_test.rb +108 -0
  89. data/test/vagrant/actions/vm/reload_test.rb +47 -0
  90. data/test/vagrant/actions/vm/resume_test.rb +27 -0
  91. data/test/vagrant/actions/vm/shared_folders_test.rb +176 -0
  92. data/test/vagrant/actions/vm/start_test.rb +36 -0
  93. data/test/vagrant/actions/vm/suspend_test.rb +27 -0
  94. data/test/vagrant/actions/vm/up_test.rb +107 -0
  95. data/test/vagrant/active_list_test.rb +190 -0
  96. data/test/vagrant/box_test.rb +151 -0
  97. data/test/vagrant/busy_test.rb +83 -0
  98. data/test/vagrant/commands_test.rb +307 -0
  99. data/test/vagrant/config_test.rb +256 -0
  100. data/test/vagrant/downloaders/base_test.rb +27 -0
  101. data/test/vagrant/downloaders/file_test.rb +26 -0
  102. data/test/vagrant/downloaders/http_test.rb +40 -0
  103. data/test/vagrant/environment_test.rb +607 -0
  104. data/test/vagrant/provisioners/base_test.rb +33 -0
  105. data/test/vagrant/provisioners/chef_server_test.rb +187 -0
  106. data/test/vagrant/provisioners/chef_solo_test.rb +149 -0
  107. data/test/vagrant/provisioners/chef_test.rb +117 -0
  108. data/test/vagrant/ssh_test.rb +222 -0
  109. data/test/vagrant/util/errors_test.rb +57 -0
  110. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  111. data/test/vagrant/util/template_renderer_test.rb +138 -0
  112. data/test/vagrant/util_test.rb +64 -0
  113. data/test/vagrant/vm_test.rb +114 -0
  114. data/vagrant.gemspec +216 -0
  115. metadata +285 -0
@@ -0,0 +1,83 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class BusyTest < Test::Unit::TestCase
4
+ context "waiting for not busy" do
5
+ setup do
6
+ Vagrant::Busy.reset_trap_thread!
7
+ end
8
+
9
+ should "run in a thread" do
10
+ Thread.expects(:new).once.returns(nil)
11
+ Vagrant::Busy.wait_for_not_busy
12
+ end
13
+
14
+ should "not start a thread multiple times" do
15
+ Thread.expects(:new).once.returns("foo")
16
+ Vagrant::Busy.wait_for_not_busy
17
+ end
18
+ end
19
+
20
+ context "during an action in a busy block" do
21
+ should "report as busy" do
22
+ Vagrant.busy do
23
+ # Inside the block Vagrant.busy? should be true
24
+ assert Vagrant.busy?
25
+ end
26
+
27
+ #After the block finishes Vagrant.busy? should be false
28
+ assert !Vagrant.busy?
29
+ end
30
+
31
+ should "set busy to false upon exception and reraise the error" do
32
+ assert_raise Exception do
33
+ Vagrant.busy do
34
+ assert Vagrant.busy?
35
+ raise Exception
36
+ end
37
+ end
38
+
39
+ assert !Vagrant.busy?
40
+ end
41
+
42
+ should "complete the trap thread even if an exception occurs" do
43
+ trap_thread = mock("trap_thread")
44
+ trap_thread.expects(:join).once
45
+ Vagrant::Busy.stubs(:trap_thread).returns(trap_thread)
46
+
47
+ assert_raise Exception do
48
+ Vagrant.busy do
49
+ raise Exception
50
+ end
51
+ end
52
+ end
53
+
54
+ should "report busy to the outside world regardless of thread" do
55
+ Thread.new do
56
+ Vagrant.busy do
57
+ sleep(2)
58
+ end
59
+ end
60
+ # Give the thread time to start
61
+ sleep(1)
62
+
63
+ # While the above thread is executing vagrant should be busy
64
+ assert Vagrant.busy?
65
+ end
66
+
67
+ should "run the action in a new thread" do
68
+ runner_thread = nil
69
+ Vagrant.busy do
70
+ runner_thread = Thread.current
71
+ end
72
+
73
+ assert_not_equal Thread.current, runner_thread
74
+ end
75
+
76
+ should "trap INT" do
77
+ trap_seq = sequence("trap_seq")
78
+ Signal.expects(:trap).with("INT", anything).once.in_sequence(trap_seq)
79
+ Signal.expects(:trap).with("INT", "DEFAULT").once.in_sequence(trap_seq)
80
+ Vagrant.busy do; end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,307 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class CommandsTest < Test::Unit::TestCase
4
+ setup do
5
+ @persisted_vm = mock("persisted_vm")
6
+ @persisted_vm.stubs(:execute!)
7
+
8
+ @env = mock_environment
9
+ @env.stubs(:vm).returns(@persisted_vm)
10
+ @env.stubs(:require_persisted_vm)
11
+ Vagrant::Environment.stubs(:load!).returns(@env)
12
+ end
13
+
14
+ context "instance methods" do
15
+ setup do
16
+ @commands = Vagrant::Commands.new(@env)
17
+ end
18
+
19
+ context "initialization" do
20
+ should "set up the environment variable" do
21
+ env = mock("env")
22
+ command = Vagrant::Commands.new(env)
23
+ assert_equal env, command.env
24
+ end
25
+ end
26
+
27
+ context "up" do
28
+ setup do
29
+ @new_vm = mock("vm")
30
+ @new_vm.stubs(:execute!)
31
+
32
+ @env.stubs(:vm).returns(nil)
33
+ @env.stubs(:require_box)
34
+ @env.stubs(:create_vm).returns(@new_vm)
35
+ end
36
+
37
+ should "require a box" do
38
+ @env.expects(:require_box).once
39
+ @commands.up
40
+ end
41
+
42
+ should "call the up action on VM if it doesn't exist" do
43
+ @new_vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once
44
+ @commands.up
45
+ end
46
+
47
+ should "call start on the persisted vm if it exists" do
48
+ @env.stubs(:vm).returns(@persisted_vm)
49
+ @persisted_vm.expects(:start).once
50
+ @env.expects(:create_vm).never
51
+ @commands.up
52
+ end
53
+ end
54
+
55
+ context "down" do
56
+ setup do
57
+ @persisted_vm.stubs(:destroy)
58
+ end
59
+
60
+ should "require a persisted VM" do
61
+ @env.expects(:require_persisted_vm).once
62
+ @commands.down
63
+ end
64
+
65
+ should "destroy the persisted VM and the VM image" do
66
+ @persisted_vm.expects(:destroy).once
67
+ @commands.down
68
+ end
69
+ end
70
+
71
+ context "reload" do
72
+ should "require a persisted VM" do
73
+ @env.expects(:require_persisted_vm).once
74
+ @commands.reload
75
+ end
76
+
77
+ should "call the `reload` action on the VM" do
78
+ @persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
79
+ @commands.reload
80
+ end
81
+ end
82
+
83
+ context "ssh" do
84
+ setup do
85
+ @env.ssh.stubs(:connect)
86
+ end
87
+
88
+ should "require a persisted VM" do
89
+ @env.expects(:require_persisted_vm).once
90
+ @commands.ssh
91
+ end
92
+
93
+ should "connect to SSH" do
94
+ @env.ssh.expects(:connect).once
95
+ @commands.ssh
96
+ end
97
+ end
98
+
99
+ context "halt" do
100
+ should "require a persisted VM" do
101
+ @env.expects(:require_persisted_vm).once
102
+ @commands.halt
103
+ end
104
+
105
+ should "call the `halt` action on the VM" do
106
+ @persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Halt).once
107
+ @commands.halt
108
+ end
109
+ end
110
+
111
+ context "suspend" do
112
+ setup do
113
+ @persisted_vm.stubs(:suspend)
114
+ @persisted_vm.stubs(:saved?).returns(false)
115
+ end
116
+
117
+ should "require a persisted VM" do
118
+ @env.expects(:require_persisted_vm).once
119
+ @commands.suspend
120
+ end
121
+
122
+ should "suspend the VM" do
123
+ @persisted_vm.expects(:suspend).once
124
+ @commands.suspend
125
+ end
126
+ end
127
+
128
+ context "resume" do
129
+ setup do
130
+ @persisted_vm.stubs(:resume)
131
+ @persisted_vm.stubs(:saved?).returns(true)
132
+ end
133
+
134
+ should "require a persisted VM" do
135
+ @env.expects(:require_persisted_vm).once
136
+ @commands.resume
137
+ end
138
+
139
+ should "save the state of the VM" do
140
+ @persisted_vm.expects(:resume).once
141
+ @commands.resume
142
+ end
143
+ end
144
+
145
+ context "package" do
146
+ setup do
147
+ @persisted_vm.stubs(:package)
148
+ @persisted_vm.stubs(:powered_off?).returns(true)
149
+ end
150
+
151
+ should "require a persisted vm" do
152
+ @env.expects(:require_persisted_vm).once
153
+ @commands.package
154
+ end
155
+
156
+ should "error and exit if the VM is not powered off" do
157
+ @persisted_vm.stubs(:powered_off?).returns(false)
158
+ @commands.expects(:error_and_exit).with(:vm_power_off_to_package).once
159
+ @persisted_vm.expects(:package).never
160
+ @commands.package
161
+ end
162
+
163
+ should "call package on the persisted VM" do
164
+ @persisted_vm.expects(:package).once
165
+ @commands.package
166
+ end
167
+
168
+ should "pass the out path and include_files to the package method" do
169
+ out_path = mock("out_path")
170
+ include_files = mock("include_files")
171
+ @persisted_vm.expects(:package).with(out_path, include_files).once
172
+ @commands.package(out_path, include_files)
173
+ end
174
+
175
+ should "default to an empty array when not include_files are specified" do
176
+ out_path = mock("out_path")
177
+ @persisted_vm.expects(:package).with(out_path, []).once
178
+ @commands.package(out_path)
179
+ end
180
+ end
181
+
182
+ context "box" do
183
+ setup do
184
+ @commands.stubs(:box_foo)
185
+ @commands.stubs(:box_add)
186
+ @commands.stubs(:box_remove)
187
+ end
188
+
189
+ should "error and exit if the first argument is not a valid subcommand" do
190
+ @commands.expects(:error_and_exit).with(:command_box_invalid).once
191
+ @commands.box(["foo"])
192
+ end
193
+
194
+ should "not error and exit if the first argument is a valid subcommand" do
195
+ commands = ["add", "remove", "list"]
196
+
197
+ commands.each do |command|
198
+ @commands.expects(:error_and_exit).never
199
+ @commands.expects("box_#{command}".to_sym).once
200
+ @commands.box([command])
201
+ end
202
+ end
203
+
204
+ should "forward any additional arguments" do
205
+ @commands.expects(:box_add).with(@env, 1,2,3).once
206
+ @commands.box(["add",1,2,3])
207
+ end
208
+ end
209
+
210
+ context "box list" do
211
+ setup do
212
+ @boxes = ["foo", "bar"]
213
+
214
+ Vagrant::Box.stubs(:all).returns(@boxes)
215
+ @commands.stubs(:wrap_output)
216
+ end
217
+
218
+ should "call all on box and sort the results" do
219
+ @all = mock("all")
220
+ @all.expects(:sort).returns(@boxes)
221
+ Vagrant::Box.expects(:all).with(@env).returns(@all)
222
+ @commands.box_list(@env)
223
+ end
224
+ end
225
+
226
+ context "box add" do
227
+ setup do
228
+ @name = "foo"
229
+ @path = "bar"
230
+ end
231
+
232
+ should "execute the add action with the name and path" do
233
+ Vagrant::Box.expects(:add).with(@env, @name, @path).once
234
+ @commands.box_add(@env, @name, @path)
235
+ end
236
+ end
237
+
238
+ context "box remove" do
239
+ setup do
240
+ @name = "foo"
241
+ end
242
+
243
+ should "error and exit if the box doesn't exist" do
244
+ Vagrant::Box.expects(:find).returns(nil)
245
+ @commands.expects(:error_and_exit).with(:box_remove_doesnt_exist).once
246
+ @commands.box_remove(@env, @name)
247
+ end
248
+
249
+ should "call destroy on the box if it exists" do
250
+ @box = mock("box")
251
+ Vagrant::Box.expects(:find).with(@env, @name).returns(@box)
252
+ @box.expects(:destroy).once
253
+ @commands.box_remove(@env, @name)
254
+ end
255
+ end
256
+ end
257
+
258
+ context "class methods" do
259
+ context "init" do
260
+ setup do
261
+ @file = mock("file")
262
+ @file.stubs(:write)
263
+ File.stubs(:open).yields(@file)
264
+ @rootfile_path = File.join(Dir.pwd, Vagrant::Environment::ROOTFILE_NAME)
265
+
266
+ Vagrant::Util::TemplateRenderer.stubs(:render)
267
+ end
268
+
269
+ should "error and exit if a rootfile already exists" do
270
+ File.expects(:exist?).with(@rootfile_path).returns(true)
271
+ Vagrant::Commands.expects(:error_and_exit).with(:rootfile_already_exists).once
272
+ Vagrant::Commands.init
273
+ end
274
+
275
+ should "write to the rootfile path using the template renderer" do
276
+ result = "foo"
277
+ Vagrant::Util::TemplateRenderer.expects(:render).returns(result).once
278
+ @file.expects(:write).with(result).once
279
+ File.expects(:open).with(@rootfile_path, 'w+').yields(@file)
280
+
281
+ Vagrant::Commands.init
282
+ end
283
+
284
+ should "use the given base box if given" do
285
+ box = "zooo"
286
+ Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => box)
287
+ Vagrant::Commands.init(box)
288
+ end
289
+
290
+ should "use the default `base` if no box is given" do
291
+ Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base")
292
+ Vagrant::Commands.init
293
+ end
294
+ end
295
+
296
+ context "executing commands in the current environment" do
297
+ should "load the environment then send the command to the commands instance" do
298
+ method = :foo
299
+ args = [1,2,3]
300
+
301
+ Vagrant::Environment.expects(:load!).returns(@env)
302
+ @env.commands.expects(:send).with(method, *args).once
303
+ Vagrant::Commands.execute(method, *args)
304
+ end
305
+ end
306
+ end
307
+ end
@@ -0,0 +1,256 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ConfigTest < Test::Unit::TestCase
4
+ context "the ssh config" do
5
+ setup do
6
+ @env = mock_environment
7
+ @env.stubs(:root_path).returns("foo")
8
+ end
9
+
10
+ should "expand any path when requesting the value" do
11
+ result = File.expand_path(@env.config.ssh[:private_key_path], @env.root_path)
12
+ assert_equal result, @env.config.ssh.private_key_path
13
+ end
14
+ end
15
+
16
+ context "adding configures" do
17
+ should "forward the method to the Top class" do
18
+ key = mock("key")
19
+ klass = mock("klass")
20
+ Vagrant::Config::Top.expects(:configures).with(key, klass)
21
+ Vagrant::Config.configures(key, klass)
22
+ end
23
+ end
24
+
25
+ context "resetting" do
26
+ setup do
27
+ Vagrant::Config.run { |config| }
28
+ Vagrant::Config.execute!
29
+ end
30
+
31
+ should "return the same config object typically" do
32
+ config = Vagrant::Config.config
33
+ assert config.equal?(Vagrant::Config.config)
34
+ end
35
+
36
+ should "create a new object if cleared" do
37
+ config = Vagrant::Config.config
38
+ Vagrant::Config.reset!
39
+ assert !config.equal?(Vagrant::Config.config)
40
+ end
41
+
42
+ should "empty the proc stack" do
43
+ assert !Vagrant::Config.proc_stack.empty?
44
+ Vagrant::Config.reset!
45
+ assert Vagrant::Config.proc_stack.empty?
46
+ end
47
+
48
+ should "reload the config object based on the given environment" do
49
+ env = mock("env")
50
+ Vagrant::Config.expects(:config).with(env).once
51
+ Vagrant::Config.reset!(env)
52
+ end
53
+ end
54
+
55
+ context "accessing configuration" do
56
+ setup do
57
+ Vagrant::Config.run { |config| }
58
+ Vagrant::Config.execute!
59
+ end
60
+
61
+ should "forward config to the class method" do
62
+ assert_equal Vagrant.config, Vagrant::Config.config
63
+ end
64
+ end
65
+
66
+ context "initializing" do
67
+ setup do
68
+ Vagrant::Config.reset!
69
+ end
70
+
71
+ should "add the given block to the proc stack" do
72
+ proc = Proc.new {}
73
+ Vagrant::Config.run(&proc)
74
+ assert_equal [proc], Vagrant::Config.proc_stack
75
+ end
76
+
77
+ should "run the proc stack with the config when execute is called" do
78
+ Vagrant::Config.expects(:run_procs!).with(Vagrant::Config.config).once
79
+ Vagrant::Config.execute!
80
+ end
81
+
82
+ should "not be loaded, initially" do
83
+ assert !Vagrant::Config.config.loaded?
84
+ end
85
+
86
+ should "be loaded after running" do
87
+ Vagrant::Config.run {}
88
+ Vagrant::Config.execute!
89
+ assert Vagrant::Config.config.loaded?
90
+ end
91
+
92
+ should "return the configuration on execute!" do
93
+ Vagrant::Config.run {}
94
+ result = Vagrant::Config.execute!
95
+ assert result.equal?(Vagrant.config)
96
+ end
97
+ end
98
+
99
+ context "base class" do
100
+ setup do
101
+ @base = Vagrant::Config::Base.new
102
+ end
103
+
104
+ should "forward [] access to methods" do
105
+ @base.expects(:foo).once
106
+ @base[:foo]
107
+ end
108
+
109
+ should "return a hash of instance variables" do
110
+ data = { :foo => "bar", :bar => "baz" }
111
+
112
+ data.each do |iv, value|
113
+ @base.instance_variable_set("@#{iv}".to_sym, value)
114
+ end
115
+
116
+ result = @base.instance_variables_hash
117
+ assert_equal data.length, result.length
118
+
119
+ data.each do |iv, value|
120
+ assert_equal value, result[iv]
121
+ end
122
+ end
123
+
124
+ should "convert instance variable hash to json" do
125
+ @json = mock("json")
126
+ @iv_hash = mock("iv_hash")
127
+ @iv_hash.expects(:to_json).once.returns(@json)
128
+ @base.expects(:instance_variables_hash).returns(@iv_hash)
129
+ assert_equal @json, @base.to_json
130
+ end
131
+ end
132
+
133
+ context "top config class" do
134
+ setup do
135
+ @configures_list = []
136
+ Vagrant::Config::Top.stubs(:configures_list).returns(@configures_list)
137
+ end
138
+
139
+ context "adding configure keys" do
140
+ setup do
141
+ @key = "top_config_foo"
142
+ @klass = mock("klass")
143
+ end
144
+
145
+ should "add key and klass to configures list" do
146
+ @configures_list.expects(:<<).with([@key, @klass])
147
+ Vagrant::Config::Top.configures(@key, @klass)
148
+ end
149
+ end
150
+
151
+ context "configuration keys on instance" do
152
+ setup do
153
+ @configures_list.clear
154
+ end
155
+
156
+ should "initialize each configurer and set it to its key" do
157
+ env = mock('env')
158
+
159
+ 5.times do |i|
160
+ key = "key#{i}"
161
+ klass = mock("klass#{i}")
162
+ instance = mock("instance#{i}")
163
+ instance.expects(:env=).with(env)
164
+ klass.expects(:new).returns(instance)
165
+ @configures_list << [key, klass]
166
+ end
167
+
168
+ Vagrant::Config::Top.new(env)
169
+ end
170
+
171
+ should "allow reading via methods" do
172
+ key = "my_foo_bar_key"
173
+ klass = mock("klass")
174
+ instance = mock("instance")
175
+ instance.stubs(:env=)
176
+ klass.expects(:new).returns(instance)
177
+ Vagrant::Config::Top.configures(key, klass)
178
+
179
+ config = Vagrant::Config::Top.new
180
+ assert_equal instance, config.send(key)
181
+ end
182
+ end
183
+
184
+ context "loaded status" do
185
+ setup do
186
+ @top= Vagrant::Config::Top.new
187
+ end
188
+
189
+ should "not be loaded by default" do
190
+ assert !@top.loaded?
191
+ end
192
+
193
+ should "be loaded after calling loaded!" do
194
+ @top.loaded!
195
+ assert @top.loaded?
196
+ end
197
+ end
198
+ end
199
+
200
+ context "vagrant configuration" do
201
+ setup do
202
+ @config = Vagrant::Config::VagrantConfig.new
203
+ end
204
+
205
+ should "return nil if home is nil" do
206
+ File.expects(:expand_path).never
207
+ assert @config.home.nil?
208
+ end
209
+
210
+ should "expand the path if home is not nil" do
211
+ @config.home = "foo"
212
+ File.expects(:expand_path).with("foo").once.returns("result")
213
+ assert_equal "result", @config.home
214
+ end
215
+ end
216
+
217
+ context "VM configuration" do
218
+ setup do
219
+ @env = mock_environment
220
+ @config = @env.config.vm
221
+ @env.config.ssh.username = @username
222
+ end
223
+
224
+ should "include the stacked proc runner module" do
225
+ assert @config.class.included_modules.include?(Vagrant::Util::StackedProcRunner)
226
+ end
227
+
228
+ should "add the customize proc to the proc stack" do
229
+ proc = Proc.new {}
230
+ @config.customize(&proc)
231
+ assert_equal [proc], @config.proc_stack
232
+ end
233
+
234
+ context "uid/gid" do
235
+ should "return the shared folder UID if set" do
236
+ @config.shared_folder_uid = "foo"
237
+ assert_equal "foo", @config.shared_folder_uid
238
+ end
239
+
240
+ should "return the SSH username if UID not set" do
241
+ @config.shared_folder_uid = nil
242
+ assert_equal @username, @config.shared_folder_uid
243
+ end
244
+
245
+ should "return the shared folder GID if set" do
246
+ @config.shared_folder_gid = "foo"
247
+ assert_equal "foo", @config.shared_folder_gid
248
+ end
249
+
250
+ should "return the SSH username if GID not set" do
251
+ @config.shared_folder_gid = nil
252
+ assert_equal @username, @config.shared_folder_gid
253
+ end
254
+ end
255
+ end
256
+ end