vagrantup 0.1.0
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.
- 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,92 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class BoxTest < Test::Unit::TestCase
|
4
|
+
context "class methods" do
|
5
|
+
context "finding" do
|
6
|
+
setup do
|
7
|
+
@dir = "foo"
|
8
|
+
@name = "bar"
|
9
|
+
Vagrant::Box.stubs(:directory).with(@name).returns(@dir)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "return nil if the box doesn't exist" do
|
13
|
+
File.expects(:directory?).with(@dir).once.returns(false)
|
14
|
+
assert_nil Vagrant::Box.find(@name)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "return a box object with the proper name set" do
|
18
|
+
File.expects(:directory?).with(@dir).once.returns(true)
|
19
|
+
result = Vagrant::Box.find(@name)
|
20
|
+
assert result
|
21
|
+
assert_equal @name, result.name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "adding" do
|
26
|
+
setup do
|
27
|
+
@name = "foo"
|
28
|
+
@uri = "bar"
|
29
|
+
end
|
30
|
+
|
31
|
+
should "create a new instance, set the variables, and add it" do
|
32
|
+
box = mock("box")
|
33
|
+
box.expects(:name=).with(@name)
|
34
|
+
box.expects(:uri=).with(@uri)
|
35
|
+
box.expects(:add).once
|
36
|
+
Vagrant::Box.expects(:new).returns(box)
|
37
|
+
Vagrant::Box.add(@name, @uri)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "box directory" do
|
42
|
+
setup do
|
43
|
+
@name = "foo"
|
44
|
+
@box_dir = File.join(Vagrant::Env.boxes_path, @name)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "return the boxes_path joined with the name" do
|
48
|
+
assert_equal @box_dir, Vagrant::Box.directory(@name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "instance methods" do
|
54
|
+
setup do
|
55
|
+
@box = Vagrant::Box.new
|
56
|
+
end
|
57
|
+
|
58
|
+
should "execute the Add action when add is called" do
|
59
|
+
@box.expects(:execute!).with(Vagrant::Actions::Box::Add).once
|
60
|
+
@box.add
|
61
|
+
end
|
62
|
+
|
63
|
+
context "box directory" do
|
64
|
+
setup do
|
65
|
+
@box.name = "foo"
|
66
|
+
end
|
67
|
+
|
68
|
+
should "return the boxes_path joined with the name" do
|
69
|
+
result = mock("object")
|
70
|
+
Vagrant::Box.expects(:directory).with(@box.name).returns(result)
|
71
|
+
assert result.equal?(@box.directory)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "destroying" do
|
76
|
+
should "execute the destroy action" do
|
77
|
+
@box.expects(:execute!).with(Vagrant::Actions::Box::Destroy).once
|
78
|
+
@box.destroy
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "ovf file" do
|
83
|
+
setup do
|
84
|
+
@box.stubs(:directory).returns("foo")
|
85
|
+
end
|
86
|
+
|
87
|
+
should "be the directory joined with the config ovf file" do
|
88
|
+
assert_equal File.join(@box.directory, Vagrant.config.vm.box_ovf), @box.ovf_file
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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(1)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# While the above thread is executing vagrant should be busy
|
62
|
+
assert Vagrant.busy?
|
63
|
+
end
|
64
|
+
|
65
|
+
should "run the action in a new thread" do
|
66
|
+
runner_thread = nil
|
67
|
+
Vagrant.busy do
|
68
|
+
runner_thread = Thread.current
|
69
|
+
end
|
70
|
+
|
71
|
+
assert_not_equal Thread.current, runner_thread
|
72
|
+
end
|
73
|
+
|
74
|
+
should "trap INT" do
|
75
|
+
trap_seq = sequence("trap_seq")
|
76
|
+
Signal.expects(:trap).with("INT", anything).once.in_sequence(trap_seq)
|
77
|
+
Signal.expects(:trap).with("INT", "DEFAULT").once.in_sequence(trap_seq)
|
78
|
+
Vagrant.busy do; end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class CommandsTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
Vagrant::Env.stubs(:load!)
|
6
|
+
|
7
|
+
@persisted_vm = mock("persisted_vm")
|
8
|
+
@persisted_vm.stubs(:execute!)
|
9
|
+
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "init" do
|
13
|
+
setup do
|
14
|
+
File.stubs(:copy)
|
15
|
+
@rootfile_path = File.join(Dir.pwd, Vagrant::Env::ROOTFILE_NAME)
|
16
|
+
@template_path = File.join(PROJECT_ROOT, "templates", Vagrant::Env::ROOTFILE_NAME)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "error and exit if a rootfile already exists" do
|
20
|
+
File.expects(:exist?).with(@rootfile_path).returns(true)
|
21
|
+
Vagrant::Commands.expects(:error_and_exit).once
|
22
|
+
Vagrant::Commands.init
|
23
|
+
end
|
24
|
+
|
25
|
+
should "copy the templated rootfile to the current path" do
|
26
|
+
File.expects(:exist?).with(@rootfile_path).returns(false)
|
27
|
+
File.expects(:copy).with(@template_path, @rootfile_path).once
|
28
|
+
Vagrant::Commands.init
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "up" do
|
33
|
+
setup do
|
34
|
+
Vagrant::Env.stubs(:persisted_vm).returns(nil)
|
35
|
+
Vagrant::VM.stubs(:execute!)
|
36
|
+
Vagrant::Env.stubs(:require_box)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "require load the environment" do
|
40
|
+
Vagrant::Env.expects(:load!).once
|
41
|
+
Vagrant::Commands.up
|
42
|
+
end
|
43
|
+
|
44
|
+
should "require a box" do
|
45
|
+
Vagrant::Env.expects(:require_box).once
|
46
|
+
Vagrant::Commands.up
|
47
|
+
end
|
48
|
+
|
49
|
+
should "call the up action on VM if it doesn't exist" do
|
50
|
+
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::VM::Up).once
|
51
|
+
Vagrant::Commands.up
|
52
|
+
end
|
53
|
+
|
54
|
+
should "call start on the persisted vm if it exists" do
|
55
|
+
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
56
|
+
@persisted_vm.expects(:start).once
|
57
|
+
Vagrant::VM.expects(:execute!).never
|
58
|
+
Vagrant::Commands.up
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "down" do
|
63
|
+
setup do
|
64
|
+
@persisted_vm.stubs(:destroy)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "require a persisted VM" do
|
68
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
69
|
+
Vagrant::Commands.down
|
70
|
+
end
|
71
|
+
|
72
|
+
should "destroy the persisted VM and the VM image" do
|
73
|
+
@persisted_vm.expects(:destroy).once
|
74
|
+
Vagrant::Commands.down
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "reload" do
|
79
|
+
should "require a persisted VM" do
|
80
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
81
|
+
Vagrant::Commands.reload
|
82
|
+
end
|
83
|
+
|
84
|
+
should "call the `reload` action on the VM" do
|
85
|
+
@persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
|
86
|
+
Vagrant::Commands.reload
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "ssh" do
|
91
|
+
setup do
|
92
|
+
Vagrant::SSH.stubs(:connect)
|
93
|
+
end
|
94
|
+
|
95
|
+
should "require a persisted VM" do
|
96
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
97
|
+
Vagrant::Commands.ssh
|
98
|
+
end
|
99
|
+
|
100
|
+
should "connect to SSH" do
|
101
|
+
Vagrant::SSH.expects(:connect).once
|
102
|
+
Vagrant::Commands.ssh
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "halt" do
|
107
|
+
should "require a persisted VM" do
|
108
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
109
|
+
Vagrant::Commands.halt
|
110
|
+
end
|
111
|
+
|
112
|
+
should "call the `halt` action on the VM" do
|
113
|
+
@persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Halt).once
|
114
|
+
Vagrant::Commands.halt
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "suspend" do
|
119
|
+
setup do
|
120
|
+
@persisted_vm.stubs(:suspend)
|
121
|
+
@persisted_vm.stubs(:saved?).returns(false)
|
122
|
+
end
|
123
|
+
|
124
|
+
should "require a persisted VM" do
|
125
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
126
|
+
Vagrant::Commands.suspend
|
127
|
+
end
|
128
|
+
|
129
|
+
should "suspend the VM" do
|
130
|
+
@persisted_vm.expects(:suspend).once
|
131
|
+
Vagrant::Commands.suspend
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "resume" do
|
136
|
+
setup do
|
137
|
+
@persisted_vm.stubs(:resume)
|
138
|
+
@persisted_vm.stubs(:saved?).returns(true)
|
139
|
+
end
|
140
|
+
|
141
|
+
should "require a persisted VM" do
|
142
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
143
|
+
Vagrant::Commands.resume
|
144
|
+
end
|
145
|
+
|
146
|
+
should "save the state of the VM" do
|
147
|
+
@persisted_vm.expects(:resume).once
|
148
|
+
Vagrant::Commands.resume
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "package" do
|
153
|
+
setup do
|
154
|
+
@persisted_vm.stubs(:package)
|
155
|
+
@persisted_vm.stubs(:powered_off?).returns(true)
|
156
|
+
end
|
157
|
+
|
158
|
+
should "require a persisted vm" do
|
159
|
+
Vagrant::Env.expects(:require_persisted_vm).once
|
160
|
+
Vagrant::Commands.package
|
161
|
+
end
|
162
|
+
|
163
|
+
should "error and exit if the VM is not powered off" do
|
164
|
+
@persisted_vm.stubs(:powered_off?).returns(false)
|
165
|
+
Vagrant::Commands.expects(:error_and_exit).once
|
166
|
+
@persisted_vm.expects(:package).never
|
167
|
+
Vagrant::Commands.package
|
168
|
+
end
|
169
|
+
|
170
|
+
should "call package on the persisted VM" do
|
171
|
+
@persisted_vm.expects(:package).once
|
172
|
+
Vagrant::Commands.package
|
173
|
+
end
|
174
|
+
|
175
|
+
should "pass the out path and include_files to the package method" do
|
176
|
+
out_path = mock("out_path")
|
177
|
+
include_files = mock("include_files")
|
178
|
+
@persisted_vm.expects(:package).with(out_path, include_files).once
|
179
|
+
Vagrant::Commands.package(out_path, include_files)
|
180
|
+
end
|
181
|
+
|
182
|
+
should "default to an empty array when not include_files are specified" do
|
183
|
+
out_path = mock("out_path")
|
184
|
+
@persisted_vm.expects(:package).with(out_path, []).once
|
185
|
+
Vagrant::Commands.package(out_path)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "box" do
|
190
|
+
setup do
|
191
|
+
Vagrant::Commands.stubs(:box_foo)
|
192
|
+
Vagrant::Commands.stubs(:box_add)
|
193
|
+
Vagrant::Commands.stubs(:box_remove)
|
194
|
+
end
|
195
|
+
|
196
|
+
should "load the environment" do
|
197
|
+
Vagrant::Env.expects(:load!).with(:suppress_errors => true).once
|
198
|
+
Vagrant::Commands.box(["add"])
|
199
|
+
end
|
200
|
+
|
201
|
+
should "error and exit if the first argument is not 'add' or 'remove'" do
|
202
|
+
Vagrant::Commands.expects(:error_and_exit).once
|
203
|
+
Vagrant::Commands.box(["foo"])
|
204
|
+
end
|
205
|
+
|
206
|
+
should "not error and exit if the first argument is 'add' or 'remove'" do
|
207
|
+
commands = ["add", "remove"]
|
208
|
+
|
209
|
+
commands.each do |command|
|
210
|
+
Vagrant::Commands.expects(:error_and_exit).never
|
211
|
+
Vagrant::Commands.expects("box_#{command}".to_sym).once
|
212
|
+
Vagrant::Commands.box([command])
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
should "forward any additional arguments" do
|
217
|
+
Vagrant::Commands.expects(:box_add).with(1,2,3).once
|
218
|
+
Vagrant::Commands.box(["add",1,2,3])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "box add" do
|
223
|
+
setup do
|
224
|
+
@name = "foo"
|
225
|
+
@path = "bar"
|
226
|
+
end
|
227
|
+
|
228
|
+
should "execute the add action with the name and path" do
|
229
|
+
Vagrant::Box.expects(:add).with(@name, @path).once
|
230
|
+
Vagrant::Commands.box_add(@name, @path)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "box remove" do
|
235
|
+
setup do
|
236
|
+
@name = "foo"
|
237
|
+
end
|
238
|
+
|
239
|
+
should "error and exit if the box doesn't exist" do
|
240
|
+
Vagrant::Box.expects(:find).returns(nil)
|
241
|
+
Vagrant::Commands.expects(:error_and_exit).once
|
242
|
+
Vagrant::Commands.box_remove(@name)
|
243
|
+
end
|
244
|
+
|
245
|
+
should "call destroy on the box if it exists" do
|
246
|
+
@box = mock("box")
|
247
|
+
Vagrant::Box.expects(:find).with(@name).returns(@box)
|
248
|
+
@box.expects(:destroy).once
|
249
|
+
Vagrant::Commands.box_remove(@name)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class ConfigTest < Test::Unit::TestCase
|
4
|
+
context "resetting" do
|
5
|
+
setup do
|
6
|
+
Vagrant::Config.run { |config| }
|
7
|
+
Vagrant::Config.execute!
|
8
|
+
end
|
9
|
+
|
10
|
+
should "return the same config object typically" do
|
11
|
+
config = Vagrant::Config.config
|
12
|
+
assert config.equal?(Vagrant::Config.config)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "create a new object if cleared" do
|
16
|
+
config = Vagrant::Config.config
|
17
|
+
Vagrant::Config.reset!
|
18
|
+
assert !config.equal?(Vagrant::Config.config)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "empty the runners" do
|
22
|
+
assert !Vagrant::Config.config_runners.empty?
|
23
|
+
Vagrant::Config.reset!
|
24
|
+
assert Vagrant::Config.config_runners.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "accessing configuration" do
|
29
|
+
setup do
|
30
|
+
Vagrant::Config.run { |config| }
|
31
|
+
Vagrant::Config.execute!
|
32
|
+
end
|
33
|
+
|
34
|
+
should "forward config to the class method" do
|
35
|
+
assert_equal Vagrant.config, Vagrant::Config.config
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "initializing" do
|
40
|
+
teardown do
|
41
|
+
Vagrant::Config.instance_variable_set(:@config_runners, nil)
|
42
|
+
Vagrant::Config.instance_variable_set(:@config, nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "not run the blocks right away" do
|
46
|
+
obj = mock("obj")
|
47
|
+
obj.expects(:foo).never
|
48
|
+
Vagrant::Config.run { |config| obj.foo }
|
49
|
+
Vagrant::Config.run { |config| obj.foo }
|
50
|
+
Vagrant::Config.run { |config| obj.foo }
|
51
|
+
end
|
52
|
+
|
53
|
+
should "run the blocks when execute! is ran" do
|
54
|
+
obj = mock("obj")
|
55
|
+
obj.expects(:foo).times(2)
|
56
|
+
Vagrant::Config.run { |config| obj.foo }
|
57
|
+
Vagrant::Config.run { |config| obj.foo }
|
58
|
+
Vagrant::Config.execute!
|
59
|
+
end
|
60
|
+
|
61
|
+
should "run the blocks with the same config object" do
|
62
|
+
Vagrant::Config.run { |config| assert config }
|
63
|
+
Vagrant::Config.run { |config| assert config }
|
64
|
+
Vagrant::Config.execute!
|
65
|
+
end
|
66
|
+
|
67
|
+
should "not be loaded, initially" do
|
68
|
+
assert !Vagrant::Config.config.loaded?
|
69
|
+
end
|
70
|
+
|
71
|
+
should "be loaded after running" do
|
72
|
+
Vagrant::Config.run {}
|
73
|
+
Vagrant::Config.execute!
|
74
|
+
assert Vagrant::Config.config.loaded?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "base class" do
|
79
|
+
setup do
|
80
|
+
@base = Vagrant::Config::Base.new
|
81
|
+
end
|
82
|
+
|
83
|
+
should "forward [] access to methods" do
|
84
|
+
@base.expects(:foo).once
|
85
|
+
@base[:foo]
|
86
|
+
end
|
87
|
+
|
88
|
+
should "return a hash of instance variables" do
|
89
|
+
data = { :foo => "bar", :bar => "baz" }
|
90
|
+
|
91
|
+
data.each do |iv, value|
|
92
|
+
@base.instance_variable_set("@#{iv}".to_sym, value)
|
93
|
+
end
|
94
|
+
|
95
|
+
result = @base.instance_variables_hash
|
96
|
+
assert_equal data.length, result.length
|
97
|
+
|
98
|
+
data.each do |iv, value|
|
99
|
+
assert_equal value, result[iv]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
should "convert instance variable hash to json" do
|
104
|
+
@json = mock("json")
|
105
|
+
@iv_hash = mock("iv_hash")
|
106
|
+
@iv_hash.expects(:to_json).once.returns(@json)
|
107
|
+
@base.expects(:instance_variables_hash).returns(@iv_hash)
|
108
|
+
assert_equal @json, @base.to_json
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "chef config" do
|
113
|
+
setup do
|
114
|
+
@config = Vagrant::Config::ChefConfig.new
|
115
|
+
@config.json = "HEY"
|
116
|
+
end
|
117
|
+
|
118
|
+
should "not include the 'json' key in the config dump" do
|
119
|
+
result = JSON.parse(@config.to_json)
|
120
|
+
assert !result.has_key?("json")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|