3
require File.dirname(__FILE__) + '/../spec_helper'
5
describe Puppet::Module, " when building its search path" do
8
it "should fully qualify unqualified paths in the search path" do
9
Puppet[:modulepath] = "something:/my/something"
10
File.stubs(:directory?).returns(true)
11
Puppet::Module.modulepath.should == [File.join(Dir.getwd, 'something'), "/my/something"]
14
it "should ignore paths that do not exist" do
15
Puppet[:modulepath] = "/yes:/no"
16
File.expects(:directory?).with("/yes").returns(true)
17
File.expects(:directory?).with("/no").returns(false)
18
Puppet::Module.modulepath.should == %w{/yes}
21
it "should prepend PUPPETLIB in search path when set" do
22
Puppet[:modulepath] = "/my/mod:/other/mod"
23
ENV["PUPPETLIB"] = "/env/mod:/myenv/mod"
24
File.stubs(:directory?).returns(true)
25
Puppet::Module.modulepath.should == %w{/env/mod /myenv/mod /my/mod /other/mod}
28
it "should use the environment-specific search path when a node environment is provided" do
29
Puppet.settings.expects(:value).with(:modulepath, "myenv").returns("/mone:/mtwo")
30
File.stubs(:directory?).returns(true)
31
Puppet::Module.modulepath("myenv").should == %w{/mone /mtwo}
35
ENV["PUPPETLIB"] = nil
39
describe Puppet::Module, " when searching for modules" do
40
it "should find modules in the search path" do
42
Puppet::Module.stubs(:modulepath).returns(path)
43
File.stubs(:directory?).returns(true)
44
mod = Puppet::Module.find("mymod")
45
mod.should be_an_instance_of(Puppet::Module)
46
mod.path.should == "/dir/path/mymod"
49
it "should not search for fully qualified modules" do
51
Puppet::Module.expects(:modulepath).never
52
File.expects(:directory?).never
53
Puppet::Module.find("/mymod").should be_nil
56
it "should search for modules in the order specified in the search path" do
57
Puppet[:modulepath] = "/one:/two:/three"
58
Puppet::Module.stubs(:modulepath).returns %w{/one /two /three}
59
File.expects(:directory?).with("/one/mod").returns(false)
60
File.expects(:directory?).with("/two/mod").returns(true)
61
File.expects(:directory?).with("/three/mod").never
62
mod = Puppet::Module.find("mod")
63
mod.path.should == "/two/mod"
66
it "should use a node environment if specified" do
67
Puppet::Module.expects(:modulepath).with("myenv").returns([])
68
Puppet::Module.find("mymod", "myenv")
72
describe Puppet::Module, " when searching for templates" do
73
it "should return fully-qualified templates directly" do
74
Puppet::Module.expects(:modulepath).never
75
Puppet::Module.find_template("/my/template").should == "/my/template"
78
it "should return the template from the first found module" do
79
Puppet[:modulepath] = "/one:/two"
80
File.stubs(:directory?).returns(true)
81
Puppet::Module.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
84
it "should return the file in the templatedir if it exists" do
85
Puppet.settings.expects(:value).with(:templatedir, nil).returns("/my/templates")
86
Puppet[:modulepath] = "/one:/two"
87
File.stubs(:directory?).returns(true)
88
File.stubs(:exists?).returns(true)
89
Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate"
92
it "should use the main templatedir if no module is found" do
93
Puppet.settings.expects(:value).with(:templatedir, nil).returns("/my/templates")
94
Puppet::Module.expects(:find).with("mymod", nil).returns(nil)
95
Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate"
98
it "should return unqualified templates directly in the template dir" do
99
Puppet.settings.expects(:value).with(:templatedir, nil).returns("/my/templates")
100
Puppet::Module.expects(:find).never
101
Puppet::Module.find_template("mytemplate").should == "/my/templates/mytemplate"
104
it "should use the environment templatedir if no module is found and an environment is specified" do
105
Puppet.settings.expects(:value).with(:templatedir, "myenv").returns("/myenv/templates")
106
Puppet::Module.expects(:find).with("mymod", "myenv").returns(nil)
107
Puppet::Module.find_template("mymod/mytemplate", "myenv").should == "/myenv/templates/mymod/mytemplate"
110
it "should use the node environment if specified" do
111
Puppet.settings.stubs(:value).returns.returns("/my/directory")
112
Puppet.settings.expects(:value).with(:modulepath, "myenv").returns("/my/modules")
113
File.stubs(:directory?).returns(true)
114
Puppet::Module.find_template("mymod/envtemplate", "myenv").should == "/my/modules/mymod/templates/envtemplate"
117
after { Puppet.settings.clear }
120
describe Puppet::Module, " when searching for manifests when no module is found" do
122
File.stubs(:find).returns(nil)
125
it "should not look for modules when paths are fully qualified" do
126
Puppet.expects(:value).with(:modulepath).never
127
file = "/fully/qualified/file.pp"
128
Dir.stubs(:glob).with(file).returns([file])
129
Puppet::Module.find_manifests(file)
132
it "should directly return fully qualified files" do
133
file = "/fully/qualified/file.pp"
134
Dir.stubs(:glob).with(file).returns([file])
135
Puppet::Module.find_manifests(file).should == [file]
138
it "should match against provided fully qualified patterns" do
139
pattern = "/fully/qualified/pattern/*"
140
Dir.expects(:glob).with(pattern).returns(%w{my file list})
141
Puppet::Module.find_manifests(pattern).should == %w{my file list}
144
it "should look for files relative to the current directory" do
146
Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"])
147
Puppet::Module.find_manifests("foobar/init.pp").should == ["#{cwd}/foobar/init.pp"]
150
it "should only return files, not directories" do
151
pattern = "/fully/qualified/pattern/*"
153
dir = "/my/directory"
154
Dir.expects(:glob).with(pattern).returns([file, dir])
155
FileTest.expects(:directory?).with(file).returns(false)
156
FileTest.expects(:directory?).with(dir).returns(true)
157
Puppet::Module.find_manifests(pattern).should == [file]
161
describe Puppet::Module, " when searching for manifests in a found module" do
162
it "should return the manifests from the first found module" do
163
Puppet[:modulepath] = "/one:/two"
164
File.stubs(:directory?).returns(true)
165
Dir.expects(:glob).with("/one/mymod/manifests/init.pp").returns(%w{/one/mymod/manifests/init.pp})
166
Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"]
169
it "should use the node environment if specified" do
170
Puppet.settings.expects(:value).with(:modulepath, "myenv").returns("/env/modules")
171
File.stubs(:directory?).returns(true)
172
Dir.expects(:glob).with("/env/modules/mymod/manifests/envmanifest.pp").returns(%w{/env/modules/mymod/manifests/envmanifest.pp})
173
Puppet::Module.find_manifests("mymod/envmanifest.pp", :environment => "myenv").should == ["/env/modules/mymod/manifests/envmanifest.pp"]
176
it "should return all manifests matching the glob pattern" do
177
Puppet.settings.expects(:value).with(:modulepath, nil).returns("/my/modules")
178
File.stubs(:directory?).returns(true)
179
Dir.expects(:glob).with("/my/modules/mymod/manifests/yay/*.pp").returns(%w{/one /two})
180
Puppet::Module.find_manifests("mymod/yay/*.pp").should == %w{/one /two}
183
it "should not return directories" do
184
Puppet.settings.expects(:value).with(:modulepath, nil).returns("/my/modules")
185
File.stubs(:directory?).returns(true)
186
Dir.expects(:glob).with("/my/modules/mymod/manifests/yay/*.pp").returns(%w{/one /two})
187
FileTest.expects(:directory?).with("/one").returns false
188
FileTest.expects(:directory?).with("/two").returns true
189
Puppet::Module.find_manifests("mymod/yay/*.pp").should == %w{/one}
192
it "should default to the 'init.pp' file in the manifests directory" do
193
Puppet.settings.expects(:value).with(:modulepath, nil).returns("/my/modules")
194
File.stubs(:directory?).returns(true)
195
Dir.expects(:glob).with("/my/modules/mymod/manifests/init.pp").returns(%w{my manifest})
196
Puppet::Module.find_manifests("mymod").should == %w{my manifest}
199
after { Puppet.settings.clear }
202
describe Puppet::Module, " when returning files" do
203
it "should return the path to the module's 'files' directory" do
204
mod = Puppet::Module.send(:new, "mymod", "/my/mod")
205
mod.files.should == "/my/mod/files"