bmabey-vagrant 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +17 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/bin/.gitignore +0 -0
- data/bin/vagrant +15 -0
- data/bin/vagrant-box +34 -0
- data/bin/vagrant-down +27 -0
- data/bin/vagrant-halt +28 -0
- data/bin/vagrant-init +27 -0
- data/bin/vagrant-package +29 -0
- data/bin/vagrant-reload +29 -0
- data/bin/vagrant-resume +27 -0
- data/bin/vagrant-ssh +27 -0
- data/bin/vagrant-status +29 -0
- data/bin/vagrant-suspend +27 -0
- data/bin/vagrant-up +29 -0
- data/config/default.rb +26 -0
- data/keys/README.md +10 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +19 -0
- data/lib/vagrant/actions/base.rb +118 -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 +72 -0
- data/lib/vagrant/actions/box/unpackage.rb +43 -0
- data/lib/vagrant/actions/collection.rb +36 -0
- data/lib/vagrant/actions/runner.rb +132 -0
- data/lib/vagrant/actions/vm/boot.rb +47 -0
- data/lib/vagrant/actions/vm/customize.rb +17 -0
- data/lib/vagrant/actions/vm/destroy.rb +23 -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 +46 -0
- data/lib/vagrant/actions/vm/halt.rb +14 -0
- data/lib/vagrant/actions/vm/import.rb +18 -0
- data/lib/vagrant/actions/vm/move_hard_drive.rb +51 -0
- data/lib/vagrant/actions/vm/package.rb +65 -0
- data/lib/vagrant/actions/vm/provision.rb +49 -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 +81 -0
- data/lib/vagrant/actions/vm/start.rb +18 -0
- data/lib/vagrant/actions/vm/suspend.rb +16 -0
- data/lib/vagrant/actions/vm/up.rb +40 -0
- data/lib/vagrant/active_list.rb +73 -0
- data/lib/vagrant/box.rb +152 -0
- data/lib/vagrant/busy.rb +73 -0
- data/lib/vagrant/commands.rb +219 -0
- data/lib/vagrant/config.rb +183 -0
- data/lib/vagrant/downloaders/base.rb +16 -0
- data/lib/vagrant/downloaders/file.rb +17 -0
- data/lib/vagrant/downloaders/http.rb +47 -0
- data/lib/vagrant/environment.rb +263 -0
- data/lib/vagrant/provisioners/base.rb +29 -0
- data/lib/vagrant/provisioners/chef.rb +103 -0
- data/lib/vagrant/provisioners/chef_server.rb +84 -0
- data/lib/vagrant/provisioners/chef_solo.rb +97 -0
- data/lib/vagrant/ssh.rb +104 -0
- data/lib/vagrant/util.rb +51 -0
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +61 -0
- data/templates/Vagrantfile.erb +8 -0
- data/templates/errors.yml +117 -0
- data/test/test_helper.rb +163 -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 +131 -0
- data/test/vagrant/actions/box/unpackage_test.rb +100 -0
- data/test/vagrant/actions/collection_test.rb +110 -0
- data/test/vagrant/actions/runner_test.rb +265 -0
- data/test/vagrant/actions/vm/boot_test.rb +55 -0
- data/test/vagrant/actions/vm/customize_test.rb +16 -0
- data/test/vagrant/actions/vm/destroy_test.rb +36 -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 +104 -0
- data/test/vagrant/actions/vm/halt_test.rb +27 -0
- data/test/vagrant/actions/vm/import_test.rb +43 -0
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +108 -0
- data/test/vagrant/actions/vm/package_test.rb +181 -0
- data/test/vagrant/actions/vm/provision_test.rb +108 -0
- data/test/vagrant/actions/vm/reload_test.rb +47 -0
- data/test/vagrant/actions/vm/resume_test.rb +27 -0
- data/test/vagrant/actions/vm/shared_folders_test.rb +176 -0
- data/test/vagrant/actions/vm/start_test.rb +36 -0
- data/test/vagrant/actions/vm/suspend_test.rb +27 -0
- data/test/vagrant/actions/vm/up_test.rb +107 -0
- data/test/vagrant/active_list_test.rb +190 -0
- data/test/vagrant/box_test.rb +151 -0
- data/test/vagrant/busy_test.rb +83 -0
- data/test/vagrant/commands_test.rb +307 -0
- data/test/vagrant/config_test.rb +256 -0
- data/test/vagrant/downloaders/base_test.rb +27 -0
- data/test/vagrant/downloaders/file_test.rb +26 -0
- data/test/vagrant/downloaders/http_test.rb +40 -0
- data/test/vagrant/environment_test.rb +607 -0
- data/test/vagrant/provisioners/base_test.rb +33 -0
- data/test/vagrant/provisioners/chef_server_test.rb +187 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +149 -0
- data/test/vagrant/provisioners/chef_test.rb +117 -0
- data/test/vagrant/ssh_test.rb +222 -0
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/util_test.rb +64 -0
- data/test/vagrant/vm_test.rb +114 -0
- data/vagrant.gemspec +216 -0
- metadata +285 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class StartActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Start)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "sub-actions" do
|
10
|
+
setup do
|
11
|
+
@vm.stubs(:saved?).returns(true)
|
12
|
+
File.stubs(:file?).returns(true)
|
13
|
+
File.stubs(:exist?).returns(true)
|
14
|
+
@default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_action_expectations
|
18
|
+
default_seq = sequence("default_seq")
|
19
|
+
@default_order.each do |action|
|
20
|
+
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should "do the proper actions by default" do
|
25
|
+
setup_action_expectations
|
26
|
+
@action.prepare
|
27
|
+
end
|
28
|
+
|
29
|
+
should "add customize to the beginning if its not saved" do
|
30
|
+
@vm.expects(:saved?).returns(false)
|
31
|
+
@default_order.unshift(Vagrant::Actions::VM::Customize)
|
32
|
+
setup_action_expectations
|
33
|
+
@action.prepare
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class SuspendActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Suspend)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "executing" do
|
10
|
+
setup do
|
11
|
+
@vm.stubs(:running?).returns(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "save the state of the VM" do
|
15
|
+
@vm.expects(:save_state).with(true).once
|
16
|
+
@action.execute!
|
17
|
+
end
|
18
|
+
|
19
|
+
should "raise an ActionException if the VM is not running" do
|
20
|
+
@vm.expects(:running?).returns(false)
|
21
|
+
@vm.expects(:save_state).never
|
22
|
+
assert_raises(Vagrant::Actions::ActionException) {
|
23
|
+
@action.execute!
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class UpActionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
|
6
|
+
mock_config
|
7
|
+
end
|
8
|
+
|
9
|
+
context "sub-actions" do
|
10
|
+
setup do
|
11
|
+
File.stubs(:file?).returns(true)
|
12
|
+
File.stubs(:exist?).returns(true)
|
13
|
+
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
14
|
+
|
15
|
+
@dotfile_path = "foo"
|
16
|
+
@runner.env.stubs(:dotfile_path).returns(@dotfile_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_action_expectations
|
20
|
+
default_seq = sequence("default_seq")
|
21
|
+
@default_order.each do |action|
|
22
|
+
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
should "raise an ActionException if a dotfile exists but is not a file" do
|
27
|
+
File.expects(:file?).with(@runner.env.dotfile_path).returns(false)
|
28
|
+
assert_raises(Vagrant::Actions::ActionException) {
|
29
|
+
@action.prepare
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
should "not raise an ActionException if dotfile doesn't exist" do
|
34
|
+
setup_action_expectations
|
35
|
+
File.stubs(:exist?).returns(false)
|
36
|
+
assert_nothing_raised { @action.prepare }
|
37
|
+
end
|
38
|
+
|
39
|
+
should "not raise an ActionException if dotfile exists but is a file" do
|
40
|
+
File.stubs(:file?).returns(true)
|
41
|
+
File.stubs(:exist?).returns(true)
|
42
|
+
setup_action_expectations
|
43
|
+
assert_nothing_raised { @action.prepare }
|
44
|
+
end
|
45
|
+
|
46
|
+
should "do the proper actions by default" do
|
47
|
+
setup_action_expectations
|
48
|
+
@action.prepare
|
49
|
+
end
|
50
|
+
|
51
|
+
should "add in the provisioning step if enabled" do
|
52
|
+
env = mock_environment do |config|
|
53
|
+
config.vm.provisioner = "foo"
|
54
|
+
end
|
55
|
+
|
56
|
+
@runner.stubs(:env).returns(env)
|
57
|
+
env.stubs(:dotfile_path).returns(@dotfile_path)
|
58
|
+
|
59
|
+
@default_order.push(Vagrant::Actions::VM::Provision)
|
60
|
+
setup_action_expectations
|
61
|
+
@action.prepare
|
62
|
+
end
|
63
|
+
|
64
|
+
should "add in the action to move hard drive if config is set" do
|
65
|
+
env = mock_environment do |config|
|
66
|
+
File.expects(:directory?).with("foo").returns(true)
|
67
|
+
config.vm.hd_location = "foo"
|
68
|
+
end
|
69
|
+
|
70
|
+
@runner.stubs(:env).returns(env)
|
71
|
+
env.stubs(:dotfile_path).returns(@dotfile_path)
|
72
|
+
|
73
|
+
@default_order.insert(0, Vagrant::Actions::VM::MoveHardDrive)
|
74
|
+
setup_action_expectations
|
75
|
+
@action.prepare
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "callbacks" do
|
80
|
+
should "call persist and mac address setup after import" do
|
81
|
+
boot_seq = sequence("boot")
|
82
|
+
@action.expects(:persist).once.in_sequence(boot_seq)
|
83
|
+
@action.expects(:setup_mac_address).once.in_sequence(boot_seq)
|
84
|
+
@action.after_import
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "persisting" do
|
89
|
+
should "persist the VM with Env" do
|
90
|
+
@runner.stubs(:uuid)
|
91
|
+
@runner.env.expects(:persist_vm).once
|
92
|
+
@action.persist
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "setting up MAC address" do
|
97
|
+
should "match the mac address with the base" do
|
98
|
+
nic = mock("nic")
|
99
|
+
nic.expects(:macaddress=).once
|
100
|
+
|
101
|
+
@vm.expects(:nics).returns([nic]).once
|
102
|
+
@vm.expects(:save).with(true).once
|
103
|
+
|
104
|
+
@action.setup_mac_address
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class ActiveListTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
mock_config
|
6
|
+
|
7
|
+
@env = mock_environment
|
8
|
+
@list = Vagrant::ActiveList.new(@env)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "initializing" do
|
12
|
+
should "set the environment to nil if not specified" do
|
13
|
+
assert_nothing_raised {
|
14
|
+
list = Vagrant::ActiveList.new
|
15
|
+
assert list.env.nil?
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set the environment to the given parameter if specified" do
|
20
|
+
env = mock("env")
|
21
|
+
list = Vagrant::ActiveList.new(env)
|
22
|
+
assert_equal env, list.env
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "listing" do
|
27
|
+
setup do
|
28
|
+
@path = "foo"
|
29
|
+
@list.stubs(:path).returns(@path)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "load if reload is given" do
|
33
|
+
File.stubs(:file?).returns(true)
|
34
|
+
File.expects(:open).once
|
35
|
+
@list.list(true)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "not load if the active json file doesn't exist" do
|
39
|
+
File.expects(:file?).with(@list.path).returns(false)
|
40
|
+
File.expects(:open).never
|
41
|
+
assert_equal [], @list.list(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "parse the JSON by reading the file" do
|
45
|
+
file = mock("file")
|
46
|
+
data = mock("data")
|
47
|
+
result = mock("result")
|
48
|
+
File.expects(:file?).returns(true)
|
49
|
+
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
50
|
+
file.expects(:read).returns(data)
|
51
|
+
JSON.expects(:parse).with(data).returns(result)
|
52
|
+
assert_equal result, @list.list(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
should "not load if reload flag is false and already loaded" do
|
56
|
+
File.expects(:file?).once.returns(false)
|
57
|
+
result = @list.list(true)
|
58
|
+
assert result.equal?(@list.list)
|
59
|
+
assert result.equal?(@list.list)
|
60
|
+
assert result.equal?(@list.list)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "vms" do
|
65
|
+
setup do
|
66
|
+
@the_list = ["foo", "bar"]
|
67
|
+
@list.stubs(:list).returns(@the_list)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "return the list, but with each value as a VM" do
|
71
|
+
new_seq = sequence("new")
|
72
|
+
results = []
|
73
|
+
@the_list.each do |item|
|
74
|
+
result = mock("result-#{item}")
|
75
|
+
Vagrant::VM.expects(:find).with(item).returns(result).in_sequence(new_seq)
|
76
|
+
results << result
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_equal results, @list.vms
|
80
|
+
end
|
81
|
+
|
82
|
+
should "compact out the nil values" do
|
83
|
+
Vagrant::VM.stubs(:find).returns(nil)
|
84
|
+
results = @list.vms
|
85
|
+
assert results.empty?
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "filtered list" do
|
90
|
+
should "return a list of UUIDs from the VMs" do
|
91
|
+
vms = []
|
92
|
+
result = []
|
93
|
+
5.times do |i|
|
94
|
+
vm = mock("vm#{i}")
|
95
|
+
vm.expects(:uuid).returns(i)
|
96
|
+
result << i
|
97
|
+
vms << vm
|
98
|
+
end
|
99
|
+
|
100
|
+
@list.stubs(:vms).returns(vms)
|
101
|
+
assert_equal result, @list.filtered_list
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "adding a VM to the list" do
|
106
|
+
setup do
|
107
|
+
@the_list = []
|
108
|
+
@list.stubs(:list).returns(@the_list)
|
109
|
+
@list.stubs(:save)
|
110
|
+
|
111
|
+
@uuid = "foo"
|
112
|
+
@vm = mock("vm")
|
113
|
+
@vm.stubs(:uuid).returns(@uuid)
|
114
|
+
end
|
115
|
+
|
116
|
+
should "add the VMs UUID to the list" do
|
117
|
+
@list.add(@vm)
|
118
|
+
assert_equal [@uuid], @the_list
|
119
|
+
end
|
120
|
+
|
121
|
+
should "uniq the array so multiples never exist" do
|
122
|
+
@the_list << @uuid
|
123
|
+
assert_equal 1, @the_list.length
|
124
|
+
@list.add(@vm)
|
125
|
+
assert_equal 1, @the_list.length
|
126
|
+
end
|
127
|
+
|
128
|
+
should "save after adding" do
|
129
|
+
save_seq = sequence('save')
|
130
|
+
@the_list.expects(:<<).in_sequence(save_seq)
|
131
|
+
@list.expects(:save).in_sequence(save_seq)
|
132
|
+
@list.add(@vm)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "deleting a VM from the list" do
|
137
|
+
setup do
|
138
|
+
@the_list = ["bar"]
|
139
|
+
@list.stubs(:list).returns(@the_list)
|
140
|
+
@list.stubs(:save)
|
141
|
+
|
142
|
+
@uuid = "bar"
|
143
|
+
@vm = mock("vm")
|
144
|
+
@vm.stubs(:uuid).returns(@uuid)
|
145
|
+
@vm.stubs(:is_a?).with(Vagrant::VM).returns(true)
|
146
|
+
end
|
147
|
+
|
148
|
+
should "delete the uuid from the list of a VM" do
|
149
|
+
@list.remove(@vm)
|
150
|
+
assert @the_list.empty?
|
151
|
+
end
|
152
|
+
|
153
|
+
should "delete just the string if a string is given" do
|
154
|
+
@the_list << "zoo"
|
155
|
+
@list.remove("zoo")
|
156
|
+
assert !@the_list.include?("zoo")
|
157
|
+
end
|
158
|
+
|
159
|
+
should "save after removing" do
|
160
|
+
save_seq = sequence('save')
|
161
|
+
@the_list.expects(:delete).in_sequence(save_seq)
|
162
|
+
@list.expects(:save).in_sequence(save_seq)
|
163
|
+
@list.remove(@vm)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "saving" do
|
168
|
+
setup do
|
169
|
+
@filtered = ["zoo"]
|
170
|
+
@list.stubs(:filtered_list).returns(@filtered)
|
171
|
+
end
|
172
|
+
|
173
|
+
should "open the JSON path and save to it" do
|
174
|
+
file = mock("file")
|
175
|
+
File.expects(:open).with(@list.path, "w+").yields(file)
|
176
|
+
file.expects(:write).with(@filtered.to_json)
|
177
|
+
@list.save
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "path" do
|
182
|
+
setup do
|
183
|
+
@env.stubs(:home_path).returns("foo")
|
184
|
+
end
|
185
|
+
|
186
|
+
should "return the active file within the home path" do
|
187
|
+
assert_equal File.join(@env.home_path, Vagrant::ActiveList::FILENAME), @list.path
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class BoxTest < Test::Unit::TestCase
|
4
|
+
context "class methods" do
|
5
|
+
setup do
|
6
|
+
@env = mock_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
context "listing all boxes" do
|
10
|
+
setup do
|
11
|
+
Dir.stubs(:open)
|
12
|
+
File.stubs(:directory?).returns(true)
|
13
|
+
|
14
|
+
@boxes_path = "foo"
|
15
|
+
@env.stubs(:boxes_path).returns(@boxes_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "open the boxes directory" do
|
19
|
+
Dir.expects(:open).with(@env.boxes_path)
|
20
|
+
Vagrant::Box.all(@env)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return an array" do
|
24
|
+
result = Vagrant::Box.all(@env)
|
25
|
+
assert result.is_a?(Array)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "not return the '.' and '..' directories" do
|
29
|
+
dir = [".", "..", "..", ".", ".."]
|
30
|
+
Dir.expects(:open).yields(dir)
|
31
|
+
result = Vagrant::Box.all(@env)
|
32
|
+
assert result.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
should "return the other directories" do
|
36
|
+
dir = [".", "foo", "bar", "baz"]
|
37
|
+
Dir.expects(:open).yields(dir)
|
38
|
+
result = Vagrant::Box.all(@env)
|
39
|
+
assert_equal ["foo", "bar", "baz"], result
|
40
|
+
end
|
41
|
+
|
42
|
+
should "ignore the files" do
|
43
|
+
dir = ["foo", "bar"]
|
44
|
+
files = [true, false]
|
45
|
+
Dir.expects(:open).yields(dir)
|
46
|
+
dir_sequence = sequence("directory")
|
47
|
+
dir.each_with_index do |dir, index|
|
48
|
+
File.expects(:directory?).with(File.join(@boxes_path, dir)).returns(files[index]).in_sequence(dir_sequence)
|
49
|
+
end
|
50
|
+
|
51
|
+
result = Vagrant::Box.all(@env)
|
52
|
+
assert_equal ["foo"], result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "finding" do
|
57
|
+
setup do
|
58
|
+
@dir = "foo"
|
59
|
+
@name = "bar"
|
60
|
+
Vagrant::Box.stubs(:directory).with(@env, @name).returns(@dir)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "return nil if the box doesn't exist" do
|
64
|
+
File.expects(:directory?).with(@dir).once.returns(false)
|
65
|
+
assert_nil Vagrant::Box.find(@env, @name)
|
66
|
+
end
|
67
|
+
|
68
|
+
should "return a box object with the proper name set" do
|
69
|
+
File.expects(:directory?).with(@dir).once.returns(true)
|
70
|
+
result = Vagrant::Box.find(@env, @name)
|
71
|
+
assert result
|
72
|
+
assert_equal @name, result.name
|
73
|
+
end
|
74
|
+
|
75
|
+
should "return a box object with the proper env set" do
|
76
|
+
File.expects(:directory?).with(@dir).once.returns(true)
|
77
|
+
result = Vagrant::Box.find(@env, @name)
|
78
|
+
assert result
|
79
|
+
assert_equal @env, result.env
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "adding" do
|
84
|
+
setup do
|
85
|
+
@name = "foo"
|
86
|
+
@uri = "bar"
|
87
|
+
end
|
88
|
+
|
89
|
+
should "create a new instance, set the variables, and add it" do
|
90
|
+
box = mock("box")
|
91
|
+
box.expects(:name=).with(@name)
|
92
|
+
box.expects(:uri=).with(@uri)
|
93
|
+
box.expects(:env=).with(@env)
|
94
|
+
box.expects(:add).once
|
95
|
+
Vagrant::Box.expects(:new).returns(box)
|
96
|
+
Vagrant::Box.add(@env, @name, @uri)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "box directory" do
|
101
|
+
setup do
|
102
|
+
@name = "foo"
|
103
|
+
@box_dir = File.join(@env.boxes_path, @name)
|
104
|
+
end
|
105
|
+
|
106
|
+
should "return the boxes_path joined with the name" do
|
107
|
+
assert_equal @box_dir, Vagrant::Box.directory(@env, @name)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "instance methods" do
|
113
|
+
setup do
|
114
|
+
@box = Vagrant::Box.new
|
115
|
+
end
|
116
|
+
|
117
|
+
should "execute the Add action when add is called" do
|
118
|
+
@box.expects(:execute!).with(Vagrant::Actions::Box::Add).once
|
119
|
+
@box.add
|
120
|
+
end
|
121
|
+
|
122
|
+
context "box directory" do
|
123
|
+
setup do
|
124
|
+
@box.name = "foo"
|
125
|
+
end
|
126
|
+
|
127
|
+
should "return the boxes_path joined with the name" do
|
128
|
+
result = mock("object")
|
129
|
+
Vagrant::Box.expects(:directory).with(@box.env, @box.name).returns(result)
|
130
|
+
assert result.equal?(@box.directory)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "destroying" do
|
135
|
+
should "execute the destroy action" do
|
136
|
+
@box.expects(:execute!).with(Vagrant::Actions::Box::Destroy).once
|
137
|
+
@box.destroy
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "ovf file" do
|
142
|
+
setup do
|
143
|
+
@box.stubs(:directory).returns("foo")
|
144
|
+
end
|
145
|
+
|
146
|
+
should "be the directory joined with the config ovf file" do
|
147
|
+
assert_equal File.join(@box.directory, Vagrant.config.vm.box_ovf), @box.ovf_file
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|