forked from hashicorp/vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpackage_test.rb
84 lines (70 loc) · 2.28 KB
/
unpackage_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require "test_helper"
class UnpackageBoxActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::Box::Unpackage
@app, @env = action_env
@env["box"] = Vagrant::Box.new(vagrant_env, "foo")
@instance = @klass.new(@app, @env)
end
context "calling" do
should "call the proper chain" do
seq = sequence("sequence")
@instance.expects(:setup_box_directory).in_sequence(seq).returns(true)
@instance.expects(:decompress).in_sequence(seq)
@app.expects(:call).with(@env)
@instance.call(@env)
end
end
context "cleaning up" do
setup do
@instance.stubs(:box_directory).returns("foo")
File.stubs(:directory?).returns(false)
FileUtils.stubs(:rm_rf)
end
should "do nothing if box directory is not set" do
@instance.stubs(:box_directory).returns(nil)
File.expects(:directory?).never
FileUtils.expects(:rm_rf).never
@instance.recover(nil)
end
should "do nothing if not a directory" do
FileUtils.expects(:rm_rf).never
@instance.recover(nil)
end
should "remove the directory if exists" do
File.expects(:directory?).with(@instance.box_directory).once.returns(true)
FileUtils.expects(:rm_rf).with(@instance.box_directory).once
@instance.recover(nil)
end
end
context "setting up the box directory" do
setup do
File.stubs(:directory?).returns(false)
FileUtils.stubs(:mkdir_p)
end
should "error the environment if the box already exists" do
File.expects(:directory?).returns(true)
assert_raises(Vagrant::Errors::BoxAlreadyExists) {
@instance.setup_box_directory
}
end
should "create the directory" do
FileUtils.expects(:mkdir_p).with(@env["box"].directory).once
@instance.setup_box_directory
end
end
context "decompressing" do
setup do
@env["download.temp_path"] = "bar"
Dir.stubs(:chdir).yields
end
should "change to the box directory" do
Dir.expects(:chdir).with(@env["box"].directory)
@instance.decompress
end
should "open the tar file within the new directory, and extract it all" do
Archive::Tar::Minitar.expects(:unpack).with(@env["download.temp_path"], @env["box"].directory.to_s).once
@instance.decompress
end
end
end