-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathpackage_spec.rb
68 lines (57 loc) · 2.27 KB
/
package_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
# This tests that packaging works with a given provider.
shared_examples "provider/package" do |provider, options|
if !options[:box]
raise ArgumentError,
"box option must be specified for provider: #{provider}"
end
include_context "acceptance"
it "can't package before an up" do
expect(execute("vagrant", "package")).to exit_with(1)
end
context "with a running machine" do
before do
assert_execute("vagrant", "box", "add", "box", options[:box])
assert_execute("vagrant", "init", "box")
assert_execute("vagrant", "up", "--provider=#{provider}")
end
after do
# Just always do this just in case
execute("vagrant", "destroy", "--force", log: false)
end
it "can package and bring the box back up" do
expect(execute("vagrant", "package")).to exit_with(0)
assert_execute("vagrant", "destroy", "--force")
path = environment.workdir.join("package.box")
expect(path).to be_file
begin
# Create a new environment and bring up the packaged box
status("Testing that we can re-use the packaged box")
new_env = new_environment
assert_execute("vagrant", "box", "add", "temp", path.to_s, env: new_env)
assert_execute("vagrant", "init", "temp", env: new_env)
assert_execute("vagrant", "up", "--provider=#{provider}", env: new_env)
# Test again for GH-5780
status("Testing we can re-package again (GH-5780)")
assert_execute("vagrant", "package", env: new_env)
assert_execute("vagrant", "destroy", "--force", env: new_env)
path = new_env.workdir.join("package.box")
new_env2 = new_environment
assert_execute("vagrant", "box", "add", "temp", path.to_s, env: new_env2)
assert_execute("vagrant", "init", "temp", env: new_env2)
assert_execute("vagrant", "up", "--provider=#{provider}", env: new_env2)
assert_execute("vagrant", "destroy", "--force", env: new_env2)
ensure
if new_env
new_env.execute("vagrant", "destroy", "--force")
new_env.close
end
if new_env2
new_env2.execute("vagrant", "destroy", "--force")
new_env2.close
end
end
end
end
end