vagrantup 0.5.2 → 0.5.3
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 +4 -4
- 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 +130 -9
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class VerifyBoxActionTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Action::Box::Verify
|
|
6
|
+
@app, @env = mock_action_data
|
|
7
|
+
|
|
8
|
+
@vm = mock("vm")
|
|
9
|
+
@env["vm"] = @vm
|
|
10
|
+
@env["box"] = Vagrant::Box.new(mock_environment, "foo")
|
|
11
|
+
|
|
12
|
+
@internal_vm = mock("internal")
|
|
13
|
+
@vm.stubs(:vm).returns(@internal_vm)
|
|
14
|
+
|
|
15
|
+
@instance = @klass.new(@app, @env)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "calling" do
|
|
19
|
+
setup do
|
|
20
|
+
@env.logger.stubs(:info)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
should "continue fine if verification succeeds" do
|
|
24
|
+
seq = sequence("seq")
|
|
25
|
+
VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).in_sequence(seq)
|
|
26
|
+
@app.expects(:call).with(@env).once.in_sequence(seq)
|
|
27
|
+
@instance.call(@env)
|
|
28
|
+
assert !@env.error?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
should "halt chain if verification fails" do
|
|
32
|
+
VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).raises(Exception)
|
|
33
|
+
@app.expects(:call).with(@env).never
|
|
34
|
+
@instance.call(@env)
|
|
35
|
+
assert @env.error?
|
|
36
|
+
assert_equal :box_verification_failed, @env.error.first
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ActionBuilderTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Action::Builder
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "initializing" do
|
|
9
|
+
should "setup empty middleware stack" do
|
|
10
|
+
builder = @klass.new
|
|
11
|
+
assert builder.stack.empty?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "take block to setup stack" do
|
|
15
|
+
builder = @klass.new do
|
|
16
|
+
use Hash
|
|
17
|
+
use lambda { |i| i }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
assert !builder.stack.empty?
|
|
21
|
+
assert_equal 2, builder.stack.length
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "with an instance" do
|
|
26
|
+
setup do
|
|
27
|
+
@instance = @klass.new
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "adding to the stack" do
|
|
31
|
+
should "return self" do
|
|
32
|
+
assert @instance.equal?(@instance.use(1))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should "add to the end" do
|
|
36
|
+
@instance.use 1
|
|
37
|
+
@instance.use 2
|
|
38
|
+
assert_equal [2, [], nil], @instance.stack.last
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should "merge in other builder's stack" do
|
|
42
|
+
other = @klass.new do
|
|
43
|
+
use 2
|
|
44
|
+
use 3
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@instance.use 1
|
|
48
|
+
@instance.use other
|
|
49
|
+
assert_equal 3, @instance.stack.length
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
should "prepend a set environment task for merging middlewares if given" do
|
|
53
|
+
other = @klass.new do
|
|
54
|
+
use 1
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
@instance.use 0
|
|
58
|
+
@instance.use(other, :foo => :bar)
|
|
59
|
+
assert_equal 3, @instance.stack.length
|
|
60
|
+
assert_equal Vagrant::Action::Env::Set, @instance.stack[1].first
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "flatten" do
|
|
65
|
+
should "return the flattened format of the builder" do
|
|
66
|
+
env = Vagrant::Action::Environment.new(nil)
|
|
67
|
+
env.expects(:foo).once
|
|
68
|
+
|
|
69
|
+
func = lambda { |x| x.foo }
|
|
70
|
+
@instance.use func
|
|
71
|
+
proc = @instance.flatten
|
|
72
|
+
assert proc.respond_to?(:call)
|
|
73
|
+
proc.call(env)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "inserting" do
|
|
78
|
+
setup do
|
|
79
|
+
@instance.use "1"
|
|
80
|
+
@instance.use "2"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
should "insert at the proper numeric index" do
|
|
84
|
+
@instance.insert(1, "3")
|
|
85
|
+
assert_equal "3", @instance.stack[1].first
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
should "insert next to the proper object if given" do
|
|
89
|
+
@instance.insert("2", "3")
|
|
90
|
+
assert_equal "3", @instance.stack[1].first
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
should "be able to call insert_before as well" do
|
|
94
|
+
@instance.insert_before("1", "0")
|
|
95
|
+
assert_equal "0", @instance.stack.first.first
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
should "be able to insert_after" do
|
|
99
|
+
@instance.insert_after("1", "0")
|
|
100
|
+
assert_equal "0", @instance.stack[1].first
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
should "be able to insert_after using numeric index" do
|
|
104
|
+
@instance.insert_after(1, "0")
|
|
105
|
+
assert_equal "0", @instance.stack[2].first
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
should "raise an exception if invalid index" do
|
|
109
|
+
assert_raises(RuntimeError) {
|
|
110
|
+
@instance.insert_after("15", "0")
|
|
111
|
+
}
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context "swapping" do
|
|
116
|
+
setup do
|
|
117
|
+
@instance.use "1"
|
|
118
|
+
@instance.use "2"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
should "be able to swap using the object" do
|
|
122
|
+
@instance.swap "1", "3"
|
|
123
|
+
assert_equal "3", @instance.stack.first.first
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
should "be able to swap using the index" do
|
|
127
|
+
@instance.swap 0, "3"
|
|
128
|
+
assert_equal "3", @instance.stack.first.first
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context "deleting" do
|
|
133
|
+
setup do
|
|
134
|
+
@instance.use "1"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
should "delete the proper object" do
|
|
138
|
+
@instance.delete("1")
|
|
139
|
+
assert @instance.stack.empty?
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
should "delete by index if given" do
|
|
143
|
+
@instance.delete(0)
|
|
144
|
+
assert @instance.stack.empty?
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
context "getting an index of an object" do
|
|
149
|
+
should "return the proper index if it exists" do
|
|
150
|
+
@instance.use 1
|
|
151
|
+
@instance.use 2
|
|
152
|
+
@instance.use 3
|
|
153
|
+
assert_equal 1, @instance.index(2)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
context "converting to an app" do
|
|
158
|
+
teardown do
|
|
159
|
+
Vagrant::Action.actions.clear
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
should "preprend error halt to the chain" do
|
|
163
|
+
result = mock("result")
|
|
164
|
+
env = {:a => :b}
|
|
165
|
+
middleware = mock("middleware")
|
|
166
|
+
middleware.stubs(:is_a?).with(Class).returns(true)
|
|
167
|
+
middleware.expects(:new).with(anything, env).returns(result)
|
|
168
|
+
@instance.use middleware
|
|
169
|
+
result = @instance.to_app(env)
|
|
170
|
+
assert result.kind_of?(Vagrant::Action::Env::ErrorHalt)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
should "make non-classes lambdas" do
|
|
174
|
+
env = Vagrant::Action::Environment.new(nil)
|
|
175
|
+
env.expects(:foo).once
|
|
176
|
+
|
|
177
|
+
func = lambda { |x| x.foo }
|
|
178
|
+
@instance.use func
|
|
179
|
+
@instance.to_app(env).call(env)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
should "raise exception if given invalid middleware" do
|
|
183
|
+
@instance.use 7
|
|
184
|
+
assert_raises(RuntimeError) {
|
|
185
|
+
@instance.to_app(nil)
|
|
186
|
+
}
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
context "calling" do
|
|
191
|
+
def mock_middleware
|
|
192
|
+
middleware = Class.new do
|
|
193
|
+
def initialize(app, env)
|
|
194
|
+
@app = app
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def call(env)
|
|
198
|
+
@app.call(env)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
should "convert to an app then call with the env" do
|
|
204
|
+
mw = mock_middleware
|
|
205
|
+
mw.any_instance.expects(:call).with() do |env|
|
|
206
|
+
assert env.has_key?(:key)
|
|
207
|
+
true
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
env = Vagrant::Action::Environment.new(nil)
|
|
211
|
+
env[:key] = :value
|
|
212
|
+
|
|
213
|
+
@instance.use(mw)
|
|
214
|
+
@instance.call(env)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ErrorHaltEnvActionTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Action::Env::ErrorHalt
|
|
6
|
+
@app, @env = mock_action_data
|
|
7
|
+
@instance = @klass.new(@app, @env)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
should "continue the chain if no error" do
|
|
11
|
+
assert !@env.error?
|
|
12
|
+
@app.expects(:call).with(@env).once
|
|
13
|
+
@instance.call(@env)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
should "halt the chain if an error occured" do
|
|
17
|
+
@env.error!(:foo)
|
|
18
|
+
@app.expects(:call).never
|
|
19
|
+
@instance.call(@env)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class SetEnvActionTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Action::Env::Set
|
|
6
|
+
@app, @env = mock_action_data
|
|
7
|
+
@env.clear
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
should "merge in the given options" do
|
|
11
|
+
@klass.new(@app, @env, :foo => :bar)
|
|
12
|
+
assert_equal :bar, @env[:foo]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should "not merge in anything if not given" do
|
|
16
|
+
@klass.new(@app, @env)
|
|
17
|
+
assert @env.empty?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
should "just continue the chain" do
|
|
21
|
+
@app.expects(:call).with(@env)
|
|
22
|
+
@klass.new(@app, @env).call(@env)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ActionEnvironmentTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Action::Environment
|
|
6
|
+
@instance = @klass.new(mock_environment)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
should "default values to those on the env" do
|
|
10
|
+
@instance.env.stubs(:key).returns("value")
|
|
11
|
+
assert_equal "value", @instance["key"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "setup the logger" do
|
|
15
|
+
assert_equal @instance.env.logger, @instance.logger
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
should "not be erroneous initially" do
|
|
19
|
+
assert !@instance.error?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should "mark as erroneous" do
|
|
23
|
+
@instance.error!(:key)
|
|
24
|
+
assert_equal [:key, {}], @instance.error
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "properly report erroneous" do
|
|
28
|
+
@instance.error!(:key)
|
|
29
|
+
assert @instance.error?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should "report interrupted if interrupt error" do
|
|
33
|
+
assert !@instance.interrupted?
|
|
34
|
+
@instance.error!(:interrupt)
|
|
35
|
+
assert @instance.interrupted?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
should "have indifferent access" do
|
|
39
|
+
@instance[:foo] = :bar
|
|
40
|
+
@instance["bar"] = :baz
|
|
41
|
+
|
|
42
|
+
assert_equal :bar, @instance["foo"]
|
|
43
|
+
assert_equal :baz, @instance[:bar]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ExceptionCatcherTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Class.new
|
|
6
|
+
@klass.send(:include, Vagrant::Action::ExceptionCatcher)
|
|
7
|
+
@env = Vagrant::Action::Environment.new(mock_environment)
|
|
8
|
+
|
|
9
|
+
@instance = @klass.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
should "run block and return result if no exception" do
|
|
13
|
+
result = @instance.catch_action_exception(@env) do
|
|
14
|
+
true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
assert result
|
|
18
|
+
assert !@env.error?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "run block and return false with error environment on exception" do
|
|
22
|
+
result = @instance.catch_action_exception(@env) do
|
|
23
|
+
raise Vagrant::Action::ActionException.new(:foo, :foo => :bar)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
assert !result
|
|
27
|
+
assert @env.error?
|
|
28
|
+
assert_equal :foo, @env.error.first
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class PackageGeneralActionTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Action::General::Package
|
|
6
|
+
@app, @env = mock_action_data
|
|
7
|
+
|
|
8
|
+
@vm = mock("vm")
|
|
9
|
+
@env["vm"] = @vm
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "initializing" do
|
|
13
|
+
setup do
|
|
14
|
+
@tar_path = "foo"
|
|
15
|
+
File.stubs(:exist?).returns(false)
|
|
16
|
+
@klass.any_instance.stubs(:tar_path).returns(@tar_path)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
should "initialize fine" do
|
|
20
|
+
@klass.new(@app, @env)
|
|
21
|
+
assert !@env.error?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
should "set the output path to configured by default" do
|
|
25
|
+
@klass.new(@app, @env)
|
|
26
|
+
assert_equal @env["config"].package.name, @env["package.output"]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "not set the output path if it is already set" do
|
|
30
|
+
@env["package.output"] = "foo"
|
|
31
|
+
@klass.new(@app, @env)
|
|
32
|
+
assert_equal "foo", @env["package.output"]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should "set the included files to empty by default" do
|
|
36
|
+
@klass.new(@app, @env)
|
|
37
|
+
assert_equal [], @env["package.include"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should "not set the output path if it is already set" do
|
|
41
|
+
@env["package.include"] = "foo"
|
|
42
|
+
@klass.new(@app, @env)
|
|
43
|
+
assert_equal "foo", @env["package.include"]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "with an instance" do
|
|
48
|
+
setup do
|
|
49
|
+
File.stubs(:exist?).returns(false)
|
|
50
|
+
File.stubs(:directory?).returns(true)
|
|
51
|
+
@instance = @klass.new(@app, @env)
|
|
52
|
+
|
|
53
|
+
@env["package.directory"] = "foo"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "calling" do
|
|
57
|
+
should "call the proper methods then continue chain" do
|
|
58
|
+
seq = sequence("seq")
|
|
59
|
+
@instance.expects(:verify_included_files).in_sequence(seq).returns(true)
|
|
60
|
+
@instance.expects(:compress).in_sequence(seq)
|
|
61
|
+
@app.expects(:call).with(@env).in_sequence(seq)
|
|
62
|
+
@instance.expects(:cleanup).never
|
|
63
|
+
|
|
64
|
+
@instance.call(@env)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
should "halt the chain if verify failed" do
|
|
68
|
+
@instance.expects(:verify_included_files).returns(false)
|
|
69
|
+
@instance.expects(:compress).never
|
|
70
|
+
@app.expects(:call).never
|
|
71
|
+
|
|
72
|
+
@instance.call(@env)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
should "halt the chain if the output file already exists" do
|
|
76
|
+
File.expects(:exist?).returns(true)
|
|
77
|
+
@app.expects(:call).never
|
|
78
|
+
@instance.call(@env)
|
|
79
|
+
|
|
80
|
+
assert @env.error?
|
|
81
|
+
assert_equal :package_output_exists, @env.error.first
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
should "halt the chain if directory isn't set" do
|
|
85
|
+
@env["package.directory"] = nil
|
|
86
|
+
@app.expects(:call).never
|
|
87
|
+
@instance.call(@env)
|
|
88
|
+
|
|
89
|
+
assert @env.error?
|
|
90
|
+
assert_equal :package_requires_directory, @env.error.first
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
should "halt the chain if directory doesn't exist" do
|
|
94
|
+
File.expects(:directory?).with(@env["package.directory"]).returns(false)
|
|
95
|
+
@app.expects(:call).never
|
|
96
|
+
@instance.call(@env)
|
|
97
|
+
|
|
98
|
+
assert @env.error?
|
|
99
|
+
assert_equal :package_requires_directory, @env.error.first
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
should "run cleanup if environment errors" do
|
|
103
|
+
seq = sequence("seq")
|
|
104
|
+
@instance.expects(:verify_included_files).in_sequence(seq).returns(true)
|
|
105
|
+
@instance.expects(:compress).in_sequence(seq)
|
|
106
|
+
@app.expects(:call).with(@env).in_sequence(seq)
|
|
107
|
+
@instance.expects(:cleanup).in_sequence(seq)
|
|
108
|
+
|
|
109
|
+
@env.error!(:foo)
|
|
110
|
+
@instance.call(@env)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "cleaning up" do
|
|
115
|
+
setup do
|
|
116
|
+
File.stubs(:exist?).returns(false)
|
|
117
|
+
File.stubs(:delete)
|
|
118
|
+
|
|
119
|
+
@instance.stubs(:tar_path).returns("foo")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
should "do nothing if the file doesn't exist" do
|
|
123
|
+
File.expects(:exist?).with(@instance.tar_path).returns(false)
|
|
124
|
+
File.expects(:delete).never
|
|
125
|
+
|
|
126
|
+
@instance.cleanup
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
should "delete the packaged box if it exists" do
|
|
130
|
+
File.expects(:exist?).returns(true)
|
|
131
|
+
File.expects(:delete).with(@instance.tar_path).once
|
|
132
|
+
|
|
133
|
+
@instance.cleanup
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
context "verifying included files" do
|
|
138
|
+
setup do
|
|
139
|
+
@env["package.include"] = ["foo"]
|
|
140
|
+
File.stubs(:exist?).returns(true)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
should "error if included file is not found" do
|
|
144
|
+
File.expects(:exist?).with("foo").returns(false)
|
|
145
|
+
assert !@instance.verify_included_files
|
|
146
|
+
assert @env.error?
|
|
147
|
+
assert_equal :package_include_file_doesnt_exist, @env.error.first
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
should "return true if all exist" do
|
|
151
|
+
assert @instance.verify_included_files
|
|
152
|
+
assert !@env.error?
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context "copying include files" do
|
|
157
|
+
setup do
|
|
158
|
+
@env["package.include"] = []
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
should "do nothing if no include files are specified" do
|
|
162
|
+
assert @env["package.include"].empty?
|
|
163
|
+
FileUtils.expects(:mkdir_p).never
|
|
164
|
+
FileUtils.expects(:cp).never
|
|
165
|
+
@instance.copy_include_files
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
should "create the include directory and copy files to it" do
|
|
169
|
+
include_dir = File.join(@env["package.directory"], "include")
|
|
170
|
+
copy_seq = sequence("copy_seq")
|
|
171
|
+
FileUtils.expects(:mkdir_p).with(include_dir).once.in_sequence(copy_seq)
|
|
172
|
+
|
|
173
|
+
5.times do |i|
|
|
174
|
+
file = mock("f#{i}")
|
|
175
|
+
@env["package.include"] << file
|
|
176
|
+
FileUtils.expects(:cp).with(file, include_dir).in_sequence(copy_seq)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
@instance.copy_include_files
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
context "compression" do
|
|
184
|
+
setup do
|
|
185
|
+
@env["package.include"] = []
|
|
186
|
+
|
|
187
|
+
@tar_path = "foo"
|
|
188
|
+
@instance.stubs(:tar_path).returns(@tar_path)
|
|
189
|
+
|
|
190
|
+
@pwd = "bar"
|
|
191
|
+
FileUtils.stubs(:pwd).returns(@pwd)
|
|
192
|
+
FileUtils.stubs(:cd)
|
|
193
|
+
|
|
194
|
+
@file = mock("file")
|
|
195
|
+
File.stubs(:open).yields(@file)
|
|
196
|
+
|
|
197
|
+
@output = mock("output")
|
|
198
|
+
@tar = Archive::Tar::Minitar
|
|
199
|
+
Archive::Tar::Minitar::Output.stubs(:open).yields(@output)
|
|
200
|
+
@tar.stubs(:pack_file)
|
|
201
|
+
|
|
202
|
+
@instance.stubs(:copy_include_files)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
should "open the tar file with the tar path properly" do
|
|
206
|
+
File.expects(:open).with(@tar_path, Vagrant::Util::Platform.tar_file_options).once
|
|
207
|
+
@instance.compress
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
should "open tar file" do
|
|
211
|
+
Archive::Tar::Minitar::Output.expects(:open).with(@file).once
|
|
212
|
+
@instance.compress
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
#----------------------------------------------------------------
|
|
216
|
+
# Methods below this comment test the block yielded by Minitar open
|
|
217
|
+
#----------------------------------------------------------------
|
|
218
|
+
should "cd to the directory and append the directory" do
|
|
219
|
+
@files = []
|
|
220
|
+
compress_seq = sequence("compress_seq")
|
|
221
|
+
|
|
222
|
+
FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
|
|
223
|
+
@instance.expects(:copy_include_files).once.in_sequence(compress_seq)
|
|
224
|
+
FileUtils.expects(:cd).with(@env["package.directory"]).in_sequence(compress_seq)
|
|
225
|
+
Dir.expects(:glob).returns(@files).in_sequence(compress_seq)
|
|
226
|
+
|
|
227
|
+
5.times do |i|
|
|
228
|
+
file = mock("file#{i}")
|
|
229
|
+
@tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
|
|
230
|
+
@files << file
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq)
|
|
234
|
+
@instance.compress
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
should "pop back to the current directory even if an exception is raised" do
|
|
238
|
+
cd_seq = sequence("cd_seq")
|
|
239
|
+
FileUtils.expects(:cd).with(@env["package.directory"]).raises(Exception).in_sequence(cd_seq)
|
|
240
|
+
FileUtils.expects(:cd).with(@pwd).in_sequence(cd_seq)
|
|
241
|
+
|
|
242
|
+
assert_raises(Exception) {
|
|
243
|
+
@instance.compress
|
|
244
|
+
}
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
context "tar path" do
|
|
249
|
+
should "return proper path" do
|
|
250
|
+
assert_equal File.join(FileUtils.pwd, @env["package.output"]), @instance.tar_path
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|