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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../spec_helper'
describe Puppet::Module, " when building its search path" do
include PuppetTest
it "should ignore unqualified paths in the search path" do
Puppet[:modulepath] = "something:/my/something"
File.stubs(:directory?).returns(true)
Puppet::Module.modulepath.should == %w{/my/something}
end
it "should ignore paths that do not exist" do
Puppet[:modulepath] = "/yes:/no"
File.expects(:directory?).with("/yes").returns(true)
File.expects(:directory?).with("/no").returns(false)
Puppet::Module.modulepath.should == %w{/yes}
end
it "should prepend PUPPETLIB in search path when set" do
Puppet[:modulepath] = "/my/mod:/other/mod"
ENV["PUPPETLIB"] = "/env/mod:/myenv/mod"
File.stubs(:directory?).returns(true)
Puppet::Module.modulepath.should == %w{/env/mod /myenv/mod /my/mod /other/mod}
end
it "should use the environment-specific search path when a node environment is provided" do
Puppet.config.expects(:value).with(:modulepath, "myenv").returns("/mone:/mtwo")
File.stubs(:directory?).returns(true)
Puppet::Module.modulepath("myenv").should == %w{/mone /mtwo}
end
after do
ENV["PUPPETLIB"] = nil
end
end
describe Puppet::Module, " when searching for modules" do
it "should find modules in the search path" do
path = %w{/dir/path}
Puppet::Module.stubs(:modulepath).returns(path)
File.stubs(:directory?).returns(true)
mod = Puppet::Module.find("mymod")
mod.should be_an_instance_of(Puppet::Module)
mod.path.should == "/dir/path/mymod"
end
it "should not search for fully qualified modules" do
path = %w{/dir/path}
Puppet::Module.expects(:modulepath).never
File.expects(:directory?).never
Puppet::Module.find("/mymod").should be_nil
end
it "should search for modules in the order specified in the search path" do
Puppet[:modulepath] = "/one:/two:/three"
Puppet::Module.stubs(:modulepath).returns %w{/one /two /three}
File.expects(:directory?).with("/one/mod").returns(false)
File.expects(:directory?).with("/two/mod").returns(true)
File.expects(:directory?).with("/three/mod").never
mod = Puppet::Module.find("mod")
mod.path.should == "/two/mod"
end
it "should use a node environment if specified" do
Puppet::Module.expects(:modulepath).with("myenv").returns([])
Puppet::Module.find("mymod", "myenv")
end
end
describe Puppet::Module, " when searching for templates" do
it "should return fully-qualified templates directly" do
Puppet::Module.expects(:modulepath).never
Puppet::Module.find_template("/my/template").should == "/my/template"
end
it "should return the template from the first found module" do
Puppet[:modulepath] = "/one:/two"
File.stubs(:directory?).returns(true)
Puppet::Module.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
end
it "should use the main templatedir if no module is found" do
Puppet.config.expects(:value).with(:templatedir, nil).returns("/my/templates")
Puppet::Module.expects(:find).with("mymod", nil).returns(nil)
Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate"
end
it "should use the environment templatedir if no module is found and an environment is specified" do
Puppet.config.expects(:value).with(:templatedir, "myenv").returns("/myenv/templates")
Puppet::Module.expects(:find).with("mymod", "myenv").returns(nil)
Puppet::Module.find_template("mymod/mytemplate", "myenv").should == "/myenv/templates/mymod/mytemplate"
end
it "should use the node environment if specified" do
Puppet.config.expects(:value).with(:modulepath, "myenv").returns("/my/templates")
File.stubs(:directory?).returns(true)
Puppet::Module.find_template("mymod/envtemplate", "myenv").should == "/my/templates/mymod/templates/envtemplate"
end
after { Puppet.config.clear }
end
describe Puppet::Module, " when searching for manifests" do
it "should return the manifests from the first found module" do
Puppet[:modulepath] = "/one:/two"
File.stubs(:directory?).returns(true)
Dir.expects(:glob).with("/one/mymod/manifests/init.pp").returns(%w{/one/mymod/manifests/init.pp})
Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"]
end
it "should search the cwd if no module is found" do
Puppet[:modulepath] = "/one:/two"
File.stubs(:find).returns(nil)
cwd = Dir.getwd
Dir.expects(:glob).with("#{cwd}/mymod/init.pp").returns(["#{cwd}/mymod/init.pp"])
Puppet::Module.find_manifests("mymod/init.pp").should == ["#{cwd}/mymod/init.pp"]
end
it "should use the node environment if specified" do
Puppet.config.expects(:value).with(:modulepath, "myenv").returns("/env/modules")
File.stubs(:directory?).returns(true)
Dir.expects(:glob).with("/env/modules/mymod/manifests/envmanifest.pp").returns(%w{/env/modules/mymod/manifests/envmanifest.pp})
Puppet::Module.find_manifests("mymod/envmanifest.pp", :environment => "myenv").should == ["/env/modules/mymod/manifests/envmanifest.pp"]
end
it "should return all manifests matching the glob pattern" do
Puppet.config.expects(:value).with(:modulepath, nil).returns("/my/modules")
File.stubs(:directory?).returns(true)
Dir.expects(:glob).with("/my/modules/mymod/manifests/yay/*.pp").returns(%w{/one /two})
Puppet::Module.find_manifests("mymod/yay/*.pp").should == %w{/one /two}
end
it "should default to the 'init.pp' file in the manifests directory" do
Puppet.config.expects(:value).with(:modulepath, nil).returns("/my/modules")
File.stubs(:directory?).returns(true)
Dir.expects(:glob).with("/my/modules/mymod/manifests/init.pp").returns(%w{my manifest})
Puppet::Module.find_manifests("mymod").should == %w{my manifest}
end
after { Puppet.config.clear }
end
describe Puppet::Module, " when returning files" do
it "should return the path to the module's 'files' directory" do
mod = Puppet::Module.send(:new, "mymod", "/my/mod")
mod.files.should == "/my/mod/files"
end
end
|