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
|
require 'spec_helper'
require 'puppet/module_tool/install_directory'
describe Puppet::ModuleTool::InstallDirectory do
def expect_normal_results
results = installer.run
results[:installed_modules].length.should eq 1
results[:installed_modules][0][:module].should == "pmtacceptance-stdlib"
results[:installed_modules][0][:version][:vstring].should == "1.0.0"
results
end
it "(#15202) creates the install directory" do
target_dir = the_directory('foo', :directory? => false, :exist? => false)
target_dir.expects(:mkpath)
install = Puppet::ModuleTool::InstallDirectory.new(target_dir)
install.prepare('pmtacceptance-stdlib', '1.0.0')
end
it "(#15202) errors when the directory is not accessible" do
target_dir = the_directory('foo', :directory? => false, :exist? => false)
target_dir.expects(:mkpath).raises(Errno::EACCES)
install = Puppet::ModuleTool::InstallDirectory.new(target_dir)
expect {
install.prepare('module', '1.0.1')
}.to raise_error(
Puppet::ModuleTool::Errors::PermissionDeniedCreateInstallDirectoryError
)
end
it "(#15202) errors when an entry along the path is not a directory" do
target_dir = the_directory("foo/bar", :exist? => false, :directory? => false)
target_dir.expects(:mkpath).raises(Errno::EEXIST)
install = Puppet::ModuleTool::InstallDirectory.new(target_dir)
expect {
install.prepare('module', '1.0.1')
}.to raise_error(Puppet::ModuleTool::Errors::InstallPathExistsNotDirectoryError)
end
it "(#15202) simply re-raises an unknown error" do
target_dir = the_directory("foo/bar", :exist? => false, :directory? => false)
target_dir.expects(:mkpath).raises("unknown error")
install = Puppet::ModuleTool::InstallDirectory.new(target_dir)
expect { install.prepare('module', '1.0.1') }.to raise_error("unknown error")
end
it "(#15202) simply re-raises an unknown system call error" do
target_dir = the_directory("foo/bar", :exist? => false, :directory? => false)
target_dir.expects(:mkpath).raises(SystemCallError, "unknown")
install = Puppet::ModuleTool::InstallDirectory.new(target_dir)
expect { install.prepare('module', '1.0.1') }.to raise_error(SystemCallError)
end
def the_directory(name, options)
dir = mock("Pathname<#{name}>")
dir.stubs(:exist?).returns(options.fetch(:exist?, true))
dir.stubs(:directory?).returns(options.fetch(:directory?, true))
dir
end
end
|