vagrant 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +49 -0
- data/README.md +2 -2
- data/Rakefile +22 -0
- data/bin/.gitignore +0 -0
- data/lib/vagrant/provisioners/chef_solo.rb +1 -1
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/version.rb +1 -1
- data/templates/Vagrantfile.erb +1 -1
- data/templates/nfs/exports.erb +4 -2
- data/test/test_helper.rb +128 -0
- data/test/vagrant/action/box/destroy_test.rb +30 -0
- data/test/vagrant/action/box/download_test.rb +141 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +103 -0
- data/test/vagrant/action/box/verify_test.rb +39 -0
- data/test/vagrant/action/builder_test.rb +218 -0
- data/test/vagrant/action/env/error_halt_test.rb +21 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +45 -0
- data/test/vagrant/action/exception_catcher_test.rb +30 -0
- data/test/vagrant/action/general/package_test.rb +254 -0
- data/test/vagrant/action/vm/boot_test.rb +83 -0
- data/test/vagrant/action/vm/check_box_test.rb +48 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +29 -0
- data/test/vagrant/action/vm/destroy_test.rb +26 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
- data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
- data/test/vagrant/action/vm/discard_state_test.rb +36 -0
- data/test/vagrant/action/vm/export_test.rb +135 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
- data/test/vagrant/action/vm/halt_test.rb +69 -0
- data/test/vagrant/action/vm/import_test.rb +50 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
- data/test/vagrant/action/vm/network_test.rb +246 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
- data/test/vagrant/action/vm/nfs_test.rb +269 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/persist_test.rb +50 -0
- data/test/vagrant/action/vm/provision_test.rb +134 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +215 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action_test.rb +111 -0
- data/test/vagrant/active_list_test.rb +173 -0
- data/test/vagrant/box_test.rb +166 -0
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +139 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/box/repackage_test.rb +52 -0
- data/test/vagrant/commands/destroy_test.rb +44 -0
- data/test/vagrant/commands/halt_test.rb +50 -0
- data/test/vagrant/commands/init_test.rb +71 -0
- data/test/vagrant/commands/package_test.rb +97 -0
- data/test/vagrant/commands/provision_test.rb +60 -0
- data/test/vagrant/commands/reload_test.rb +47 -0
- data/test/vagrant/commands/resume_test.rb +44 -0
- data/test/vagrant/commands/ssh_config_test.rb +77 -0
- data/test/vagrant/commands/ssh_test.rb +129 -0
- data/test/vagrant/commands/status_test.rb +40 -0
- data/test/vagrant/commands/suspend_test.rb +44 -0
- data/test/vagrant/commands/up_test.rb +49 -0
- data/test/vagrant/config_test.rb +307 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +33 -0
- data/test/vagrant/downloaders/http_test.rb +70 -0
- data/test/vagrant/environment_test.rb +770 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +56 -0
- data/test/vagrant/hosts/linux_test.rb +56 -0
- data/test/vagrant/provisioners/base_test.rb +36 -0
- data/test/vagrant/provisioners/chef_server_test.rb +182 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
- data/test/vagrant/provisioners/chef_test.rb +178 -0
- data/test/vagrant/ssh_session_test.rb +46 -0
- data/test/vagrant/ssh_test.rb +317 -0
- data/test/vagrant/systems/linux_test.rb +179 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +145 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/util/translator_test.rb +61 -0
- data/test/vagrant/util_test.rb +27 -0
- data/test/vagrant/vm_test.rb +228 -0
- data/vagrant.gemspec +34 -0
- metadata +158 -43
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ResumeVMActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Action::VM::Resume
|
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 "run the proper methods when saved" do
|
19
|
+
@internal_vm.expects(:saved?).returns(true)
|
20
|
+
|
21
|
+
seq = sequence("seq")
|
22
|
+
@env.env.actions.expects(:run).with(Vagrant::Action::VM::Boot).once.in_sequence(seq)
|
23
|
+
@app.expects(:call).with(@env).once.in_sequence(seq)
|
24
|
+
@instance.call(@env)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "do nothing if VM is not saved" do
|
28
|
+
@internal_vm.expects(:saved?).returns(false)
|
29
|
+
|
30
|
+
@vm.expects(:start).never
|
31
|
+
@app.expects(:call).with(@env).once
|
32
|
+
@instance.call(@env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ShareFoldersVMActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Action::VM::ShareFolders
|
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
|
+
|
17
|
+
@instance = @klass.new(@app, @env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def stub_shared_folders
|
21
|
+
env = mock_environment do |config|
|
22
|
+
config.vm.shared_folders.clear
|
23
|
+
|
24
|
+
if block_given?
|
25
|
+
yield config
|
26
|
+
else
|
27
|
+
folders = [%w{foo fooguest foohost}, %w{bar barguest barhost}]
|
28
|
+
folders.each do |data|
|
29
|
+
config.vm.share_folder(*data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@env.stubs(:env).returns(env)
|
35
|
+
env.config.vm.shared_folders
|
36
|
+
end
|
37
|
+
|
38
|
+
context "calling" do
|
39
|
+
should "run the methods in the proper order" do
|
40
|
+
before_seq = sequence("before")
|
41
|
+
@instance.expects(:create_metadata).once.in_sequence(before_seq)
|
42
|
+
@app.expects(:call).with(@env).in_sequence(before_seq)
|
43
|
+
@instance.expects(:mount_shared_folders).once.in_sequence(before_seq)
|
44
|
+
@instance.expects(:setup_unison).once.in_sequence(before_seq)
|
45
|
+
|
46
|
+
@instance.call(@env)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "run only the metadata actions if erroneous environment" do
|
50
|
+
@env.error!(:foo)
|
51
|
+
|
52
|
+
before_seq = sequence("before")
|
53
|
+
@instance.expects(:create_metadata).once.in_sequence(before_seq)
|
54
|
+
@app.expects(:call).with(@env).in_sequence(before_seq)
|
55
|
+
@instance.expects(:mount_shared_folders).never
|
56
|
+
@instance.expects(:setup_unison).never
|
57
|
+
|
58
|
+
@instance.call(@env)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "collecting shared folders" do
|
63
|
+
setup do
|
64
|
+
File.stubs(:expand_path).returns("baz")
|
65
|
+
end
|
66
|
+
|
67
|
+
should "return a hash of the shared folders" do
|
68
|
+
data = {
|
69
|
+
"foo" => %W[bar baz],
|
70
|
+
"bar" => %W[foo baz]
|
71
|
+
}
|
72
|
+
|
73
|
+
stub_shared_folders do |config|
|
74
|
+
data.each do |name, value|
|
75
|
+
config.vm.share_folder(name, *value)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
result = @instance.shared_folders
|
80
|
+
assert_equal data.length, result.length
|
81
|
+
data.each do |name, value|
|
82
|
+
guest, host = value
|
83
|
+
assert_equal guest, result[name][:guestpath]
|
84
|
+
assert_equal host, result[name][:hostpath]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
should "ignore disabled shared folders" do
|
89
|
+
stub_shared_folders do |config|
|
90
|
+
config.vm.share_folder("v-foo", "/foo", "/foo")
|
91
|
+
config.vm.share_folder("v-root", "/vagrant", ".", :disabled => true)
|
92
|
+
config.vm.share_folder("v-bar", "/bar", "/bar")
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_equal 2, @instance.shared_folders.length
|
96
|
+
assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort
|
97
|
+
end
|
98
|
+
|
99
|
+
should "append sync suffix if sync enabled to a folder" do
|
100
|
+
name = "foo"
|
101
|
+
guest = "bar"
|
102
|
+
host = "baz"
|
103
|
+
|
104
|
+
stub_shared_folders do |config|
|
105
|
+
config.vm.share_folder(name, guest, host, :sync => true)
|
106
|
+
end
|
107
|
+
|
108
|
+
result = @instance.shared_folders
|
109
|
+
assert_equal "#{guest}#{@env.env.config.unison.folder_suffix}", result[name][:guestpath]
|
110
|
+
assert_equal guest, result[name][:original][:guestpath]
|
111
|
+
end
|
112
|
+
|
113
|
+
should "not destroy original hash" do
|
114
|
+
@folders = stub_shared_folders do |config|
|
115
|
+
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
116
|
+
end
|
117
|
+
|
118
|
+
folder = @folders["foo"].dup
|
119
|
+
|
120
|
+
@instance.shared_folders
|
121
|
+
assert_equal folder, @env.env.config.vm.shared_folders["foo"]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "unison shared folders" do
|
126
|
+
setup do
|
127
|
+
@folders = stub_shared_folders do |config|
|
128
|
+
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
129
|
+
config.vm.share_folder("bar", "foo", "baz")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
should "only return the folders marked for syncing" do
|
134
|
+
result = @instance.unison_folders
|
135
|
+
assert_equal 1, result.length
|
136
|
+
assert result.has_key?("foo")
|
137
|
+
assert !result.has_key?("bar")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "setting up shared folder metadata" do
|
142
|
+
setup do
|
143
|
+
stub_shared_folders
|
144
|
+
end
|
145
|
+
|
146
|
+
should "add all shared folders to the VM" do
|
147
|
+
shared_folders = []
|
148
|
+
data = %W[foo bar]
|
149
|
+
shared_folders.expects(:<<).times(data.length).with() do |sf|
|
150
|
+
hostpath = File.expand_path("#{sf.name}host", @env.env.root_path)
|
151
|
+
assert data.include?(sf.name)
|
152
|
+
assert_equal hostpath, sf.host_path
|
153
|
+
true
|
154
|
+
end
|
155
|
+
|
156
|
+
@internal_vm.stubs(:shared_folders).returns(shared_folders)
|
157
|
+
@internal_vm.expects(:save).once
|
158
|
+
|
159
|
+
@instance.create_metadata
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "mounting the shared folders" do
|
164
|
+
setup do
|
165
|
+
@folders = stub_shared_folders
|
166
|
+
@ssh = mock("ssh")
|
167
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
168
|
+
@vm.system.stubs(:mount_shared_folder)
|
169
|
+
end
|
170
|
+
|
171
|
+
should "mount all shared folders to the VM" do
|
172
|
+
mount_seq = sequence("mount_seq")
|
173
|
+
@folders.each do |name, data|
|
174
|
+
@vm.system.expects(:mount_shared_folder).with(@ssh, name, data[:guestpath]).in_sequence(mount_seq)
|
175
|
+
end
|
176
|
+
|
177
|
+
@instance.mount_shared_folders
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "setting up unison" do
|
182
|
+
setup do
|
183
|
+
@ssh = mock("ssh")
|
184
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
185
|
+
|
186
|
+
@folders = stub_shared_folders do |config|
|
187
|
+
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
188
|
+
config.vm.share_folder("bar", "foo", "baz")
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
should "do nothing if unison folders is empty" do
|
193
|
+
@instance.stubs(:unison_folders).returns({})
|
194
|
+
@vm.ssh.expects(:execute).never
|
195
|
+
@instance.setup_unison
|
196
|
+
end
|
197
|
+
|
198
|
+
should "prepare unison then create for each folder" do
|
199
|
+
seq = sequence("unison seq")
|
200
|
+
@vm.system.expects(:prepare_unison).with(@ssh).once.in_sequence(seq)
|
201
|
+
@instance.unison_folders.each do |name, data|
|
202
|
+
if data[:sync]
|
203
|
+
@vm.system.expects(:create_unison).with do |ssh, opts|
|
204
|
+
assert_equal @ssh, ssh
|
205
|
+
assert_equal data, opts
|
206
|
+
|
207
|
+
true
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
@instance.setup_unison
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SuspendVMActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Action::VM::Suspend
|
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 "run the proper methods when running" do
|
19
|
+
@internal_vm.expects(:running?).returns(true)
|
20
|
+
|
21
|
+
seq = sequence("seq")
|
22
|
+
@internal_vm.expects(:save_state).once.in_sequence(seq)
|
23
|
+
@app.expects(:call).with(@env).once.in_sequence(seq)
|
24
|
+
@instance.call(@env)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "do nothing if VM is not running" do
|
28
|
+
@internal_vm.expects(:running?).returns(false)
|
29
|
+
|
30
|
+
@internal_vm.expects(:save_state).never
|
31
|
+
@app.expects(:call).with(@env).once
|
32
|
+
@instance.call(@env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Action
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with a class" do
|
9
|
+
teardown do
|
10
|
+
@klass.actions.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to register an action" do
|
14
|
+
@klass.register(:foo, :bar)
|
15
|
+
assert @klass.actions.has_key?(:foo)
|
16
|
+
assert_equal :bar, @klass.actions[:foo]
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be able to retrieve an action using []" do
|
20
|
+
@klass.register(:foo, :bar)
|
21
|
+
assert_equal :bar, @klass[:foo]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with an instance" do
|
26
|
+
setup do
|
27
|
+
@instance = @klass.new(mock_environment)
|
28
|
+
end
|
29
|
+
|
30
|
+
teardown do
|
31
|
+
@klass.actions.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
should "raise an exception if a nil action is given" do
|
35
|
+
assert_raises(Vagrant::Exceptions::UncallableAction) { @instance.run(nil) }
|
36
|
+
assert_raises(Vagrant::Exceptions::UncallableAction) { @instance.run(:dontexist) }
|
37
|
+
end
|
38
|
+
|
39
|
+
should "run the callable item with the proper context" do
|
40
|
+
callable = mock("callable")
|
41
|
+
callable.expects(:call).with() do |env|
|
42
|
+
assert env.kind_of?(Vagrant::Action::Environment)
|
43
|
+
assert_equal @instance.env, env.env
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
@instance.run(callable)
|
48
|
+
end
|
49
|
+
|
50
|
+
should "run the callable with the passed in options if given" do
|
51
|
+
options = {
|
52
|
+
:key => :value,
|
53
|
+
:another => %W[1 2 3]
|
54
|
+
}
|
55
|
+
|
56
|
+
callable = mock("callable")
|
57
|
+
callable.expects(:call).with() do |env|
|
58
|
+
assert env.kind_of?(Vagrant::Action::Environment)
|
59
|
+
assert_equal @instance.env, env.env
|
60
|
+
|
61
|
+
options.each do |k,v|
|
62
|
+
assert_equal v, env[k]
|
63
|
+
end
|
64
|
+
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
@instance.run(callable, options)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "run the registered callable if a symbol is given" do
|
72
|
+
callable = mock("callable")
|
73
|
+
callable.expects(:call).once
|
74
|
+
|
75
|
+
@klass.register(:call, callable)
|
76
|
+
@instance.run(:call)
|
77
|
+
end
|
78
|
+
|
79
|
+
should "run the given class if a class is given" do
|
80
|
+
callable = Class.new do
|
81
|
+
def initialize(app, env); end
|
82
|
+
end
|
83
|
+
|
84
|
+
callable.any_instance.expects(:call).with() do |env|
|
85
|
+
assert_equal :foo, env[:bar]
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
@instance.run(callable, :bar => :foo)
|
90
|
+
end
|
91
|
+
|
92
|
+
should "exit if environment was marked as interrupted" do
|
93
|
+
callable = lambda do |env|
|
94
|
+
env.error!(:interrupt)
|
95
|
+
end
|
96
|
+
|
97
|
+
@instance.stubs(:error_and_exit)
|
98
|
+
@instance.expects(:exit).once
|
99
|
+
@instance.run(callable)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "error and exit if erroneous environment results" do
|
103
|
+
callable = lambda do |env|
|
104
|
+
env.error!(:key, :foo => :bar)
|
105
|
+
end
|
106
|
+
|
107
|
+
@instance.expects(:error_and_exit).with(:key, :foo => :bar)
|
108
|
+
@instance.run(callable)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ActiveListTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@env = mock_environment
|
6
|
+
@list = Vagrant::ActiveList.new(@env)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "initializing" do
|
10
|
+
should "set the environment to nil if not specified" do
|
11
|
+
assert_nothing_raised {
|
12
|
+
list = Vagrant::ActiveList.new
|
13
|
+
assert list.env.nil?
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
should "set the environment to the given parameter if specified" do
|
18
|
+
env = mock("env")
|
19
|
+
list = Vagrant::ActiveList.new(env)
|
20
|
+
assert_equal env, list.env
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "listing" do
|
25
|
+
setup do
|
26
|
+
@path = "foo"
|
27
|
+
@list.stubs(:path).returns(@path)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "load if reload is given" do
|
31
|
+
File.stubs(:file?).returns(true)
|
32
|
+
File.expects(:open).once
|
33
|
+
@list.list(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "not load if the active json file doesn't exist" do
|
37
|
+
File.expects(:file?).with(@list.path).returns(false)
|
38
|
+
File.expects(:open).never
|
39
|
+
assert_equal Hash.new, @list.list(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "parse the JSON by reading the file" do
|
43
|
+
file = mock("file")
|
44
|
+
data = mock("data")
|
45
|
+
result = { :hey => :yep }
|
46
|
+
File.expects(:file?).returns(true)
|
47
|
+
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
48
|
+
file.expects(:read).returns(data)
|
49
|
+
JSON.expects(:parse).with(data).returns(result)
|
50
|
+
assert_equal result, @list.list(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "not load if reload flag is false and already loaded" do
|
54
|
+
File.expects(:file?).once.returns(false)
|
55
|
+
result = @list.list(true)
|
56
|
+
assert result.equal?(@list.list)
|
57
|
+
assert result.equal?(@list.list)
|
58
|
+
assert result.equal?(@list.list)
|
59
|
+
end
|
60
|
+
|
61
|
+
should "be an empty hash if JSON parsing raises an exception" do
|
62
|
+
file = mock("file")
|
63
|
+
file.stubs(:read)
|
64
|
+
File.expects(:file?).returns(true)
|
65
|
+
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
66
|
+
JSON.expects(:parse).raises(Exception)
|
67
|
+
|
68
|
+
assert_nothing_raised do
|
69
|
+
assert_equal Hash.new, @list.list(true)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "filter list" do
|
75
|
+
should "remove nonexistent VMs" do
|
76
|
+
list = {}
|
77
|
+
result = {}
|
78
|
+
5.times do |i|
|
79
|
+
vm = mock("vm#{i}")
|
80
|
+
vm.stubs(:uuid).returns(i)
|
81
|
+
|
82
|
+
list[vm.uuid] = {}
|
83
|
+
|
84
|
+
found_vm = i % 2 ? nil : vm
|
85
|
+
Vagrant::VM.stubs(:find).with(vm.uuid, @env).returns(found_vm)
|
86
|
+
results[vm.uuid] = {} if found_vm
|
87
|
+
end
|
88
|
+
|
89
|
+
@list.stubs(:list).returns(list)
|
90
|
+
assert_equal result, @list.filter_list
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "adding a VM to the list" do
|
95
|
+
setup do
|
96
|
+
@the_list = {}
|
97
|
+
@list.stubs(:list).returns(@the_list)
|
98
|
+
@list.stubs(:save)
|
99
|
+
|
100
|
+
@uuid = "foo"
|
101
|
+
@vm = mock("vm")
|
102
|
+
@vm.stubs(:uuid).returns(@uuid)
|
103
|
+
end
|
104
|
+
|
105
|
+
should "add the VMs UUID to the list" do
|
106
|
+
@list.add(@vm)
|
107
|
+
assert @the_list[@uuid]
|
108
|
+
assert @the_list[@uuid].is_a?(Hash)
|
109
|
+
end
|
110
|
+
|
111
|
+
should "save after adding" do
|
112
|
+
save_seq = sequence('save')
|
113
|
+
@the_list.expects(:[]=).in_sequence(save_seq)
|
114
|
+
@list.expects(:save).in_sequence(save_seq)
|
115
|
+
@list.add(@vm)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "deleting a VM from the list" do
|
120
|
+
setup do
|
121
|
+
@the_list = ["bar"]
|
122
|
+
@list.stubs(:list).returns(@the_list)
|
123
|
+
@list.stubs(:save)
|
124
|
+
|
125
|
+
@uuid = "bar"
|
126
|
+
@vm = mock("vm")
|
127
|
+
@vm.stubs(:uuid).returns(@uuid)
|
128
|
+
@vm.stubs(:is_a?).with(Vagrant::VM).returns(true)
|
129
|
+
end
|
130
|
+
|
131
|
+
should "delete the uuid from the list of a VM" do
|
132
|
+
@list.remove(@vm)
|
133
|
+
assert @the_list.empty?
|
134
|
+
end
|
135
|
+
|
136
|
+
should "delete just the string if a string is given" do
|
137
|
+
@the_list << "zoo"
|
138
|
+
@list.remove("zoo")
|
139
|
+
assert !@the_list.include?("zoo")
|
140
|
+
end
|
141
|
+
|
142
|
+
should "save after removing" do
|
143
|
+
save_seq = sequence('save')
|
144
|
+
@the_list.expects(:delete).in_sequence(save_seq)
|
145
|
+
@list.expects(:save).in_sequence(save_seq)
|
146
|
+
@list.remove(@vm)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "saving" do
|
151
|
+
setup do
|
152
|
+
@filtered = ["zoo"]
|
153
|
+
@list.stubs(:filter_list).returns(@filtered)
|
154
|
+
end
|
155
|
+
|
156
|
+
should "open the JSON path and save to it" do
|
157
|
+
file = mock("file")
|
158
|
+
File.expects(:open).with(@list.path, "w+").yields(file)
|
159
|
+
file.expects(:write).with(@filtered.to_json)
|
160
|
+
@list.save
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "path" do
|
165
|
+
setup do
|
166
|
+
@env.stubs(:home_path).returns("foo")
|
167
|
+
end
|
168
|
+
|
169
|
+
should "return the active file within the home path" do
|
170
|
+
assert_equal File.join(@env.home_path, Vagrant::ActiveList::FILENAME), @list.path
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|