summaryrefslogtreecommitdiffstats
path: root/spec/unit/module.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-17 12:47:41 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-05-15 10:01:26 +1000
commitc6084093e67b1e415e49c192b3ac6f6b9aebc4ba (patch)
treedcff2f7076b8e5f16d727e926bf3c0b72e45e215 /spec/unit/module.rb
parent83ba0e5efe4514201c1a627ceffdaef992431734 (diff)
downloadpuppet-c6084093e67b1e415e49c192b3ac6f6b9aebc4ba.tar.gz
puppet-c6084093e67b1e415e49c192b3ac6f6b9aebc4ba.tar.xz
puppet-c6084093e67b1e415e49c192b3ac6f6b9aebc4ba.zip
Moving file-searching code out of Puppet::Module
The Module class had a bunch of code for finding manifests and templates even when not in a module, and it complicated the class unnecessarily. This moves that code to a new, hackish-but-sufficient module for just that purpose. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/module.rb')
-rwxr-xr-xspec/unit/module.rb179
1 files changed, 0 insertions, 179 deletions
diff --git a/spec/unit/module.rb b/spec/unit/module.rb
index 313de6761..17c2065eb 100755
--- a/spec/unit/module.rb
+++ b/spec/unit/module.rb
@@ -164,185 +164,6 @@ describe Puppet::Module, " when searching for modules" do
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
- mod = mock 'module'
- Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
-
- mod.expects(:template).returns("/one/mymod/templates/mytemplate")
- Puppet::Module.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
- end
-
- it "should return the file in the templatedir if it exists" do
- Puppet.settings.expects(:value).with(:templatedir, nil).returns("/my/templates")
- Puppet[:modulepath] = "/one:/two"
- File.stubs(:directory?).returns(true)
- FileTest.stubs(:exist?).returns(true)
- Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate"
- end
-
- it "should raise an error if no valid templatedir exists" do
- Puppet::Module.stubs(:templatepath).with(nil).returns(nil)
- lambda { Puppet::Module.find_template("mytemplate") }.should raise_error
- end
-
- it "should not raise an error if no valid templatedir exists and the template exists in a module" do
- mod = mock 'module'
- Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
-
- mod.expects(:template).returns("/one/mymod/templates/mytemplate")
- Puppet::Module.stubs(:templatepath).with(nil).returns(nil)
-
- 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::Module.stubs(:templatepath).with(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 return unqualified templates directly in the template dir" do
- Puppet::Module.stubs(:templatepath).with(nil).returns(["/my/templates"])
- Puppet::Module.expects(:find).never
- Puppet::Module.find_template("mytemplate").should == "/my/templates/mytemplate"
- end
-
- it "should accept relative templatedirs" do
- Puppet[:templatedir] = "my/templates"
- File.expects(:directory?).with(File.join(Dir.getwd,"my/templates")).returns(true)
- Puppet::Module.find_template("mytemplate").should == File.join(Dir.getwd,"my/templates/mytemplate")
- end
-
- it "should use the environment templatedir if no module is found and an environment is specified" do
- Puppet::Module.stubs(:templatepath).with("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 first dir from environment templatedir if no module is found and an environment is specified" do
- Puppet::Module.stubs(:templatepath).with("myenv").returns(["/myenv/templates", "/two/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 a valid dir when templatedir is a path for unqualified templates and the first dir contains template" do
- Puppet::Module.stubs(:templatepath).returns(["/one/templates", "/two/templates"])
- FileTest.expects(:exist?).with("/one/templates/mytemplate").returns(true)
- Puppet::Module.expects(:find).never
- Puppet::Module.find_template("mytemplate").should == "/one/templates/mytemplate"
- end
-
- it "should use a valid dir when templatedir is a path for unqualified templates and only second dir contains template" do
- Puppet::Module.stubs(:templatepath).returns(["/one/templates", "/two/templates"])
- FileTest.expects(:exist?).with("/one/templates/mytemplate").returns(false)
- FileTest.expects(:exist?).with("/two/templates/mytemplate").returns(true)
- Puppet::Module.expects(:find).never
- Puppet::Module.find_template("mytemplate").should == "/two/templates/mytemplate"
- end
-
- it "should use the node environment if specified" do
- mod = mock 'module'
- Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
-
- mod.expects(:template).returns("/my/modules/mymod/templates/envtemplate")
-
- Puppet::Module.find_template("mymod/envtemplate", "myenv").should == "/my/modules/mymod/templates/envtemplate"
- end
-
- after { Puppet.settings.clear }
-end
-
-describe Puppet::Module, " when searching for manifests when no module is found" do
- before do
- File.stubs(:find).returns(nil)
- end
-
- it "should not look for modules when paths are fully qualified" do
- Puppet.expects(:value).with(:modulepath).never
- file = "/fully/qualified/file.pp"
- Dir.stubs(:glob).with(file).returns([file])
- Puppet::Module.find_manifests(file)
- end
-
- it "should directly return fully qualified files" do
- file = "/fully/qualified/file.pp"
- Dir.stubs(:glob).with(file).returns([file])
- Puppet::Module.find_manifests(file).should == [file]
- end
-
- it "should match against provided fully qualified patterns" do
- pattern = "/fully/qualified/pattern/*"
- Dir.expects(:glob).with(pattern).returns(%w{my file list})
- Puppet::Module.find_manifests(pattern).should == %w{my file list}
- end
-
- it "should look for files relative to the current directory" do
- cwd = Dir.getwd
- Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"])
- Puppet::Module.find_manifests("foobar/init.pp").should == ["#{cwd}/foobar/init.pp"]
- end
-
- it "should only return files, not directories" do
- pattern = "/fully/qualified/pattern/*"
- file = "/my/file"
- dir = "/my/directory"
- Dir.expects(:glob).with(pattern).returns([file, dir])
- FileTest.expects(:directory?).with(file).returns(false)
- FileTest.expects(:directory?).with(dir).returns(true)
- Puppet::Module.find_manifests(pattern).should == [file]
- end
-end
-
-describe Puppet::Module, " when searching for manifests in a found module" do
- before do
- @module = Puppet::Module.new("mymod", "/one")
- end
-
- it "should return the manifests from the first found module" do
- mod = mock 'module'
- Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
- mod.expects(:match_manifests).with("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 use the node environment if specified" do
- mod = mock 'module'
- Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
- mod.expects(:match_manifests).with("init.pp").returns(%w{/one/mymod/manifests/init.pp})
- Puppet::Module.find_manifests("mymod/init.pp", :environment => "myenv").should == ["/one/mymod/manifests/init.pp"]
- end
-
- it "should return all manifests matching the glob pattern" do
- File.stubs(:directory?).returns(true)
- Dir.expects(:glob).with("/one/manifests/yay/*.pp").returns(%w{/one /two})
-
- @module.match_manifests("yay/*.pp").should == %w{/one /two}
- end
-
- it "should not return directories" do
- Dir.expects(:glob).with("/one/manifests/yay/*.pp").returns(%w{/one /two})
-
- FileTest.expects(:directory?).with("/one").returns false
- FileTest.expects(:directory?).with("/two").returns true
-
- @module.match_manifests("yay/*.pp").should == %w{/one}
- end
-
- it "should default to the 'init.pp' file in the manifests directory" do
- Dir.expects(:glob).with("/one/manifests/init.pp").returns(%w{/init.pp})
-
- @module.match_manifests(nil).should == %w{/init.pp}
- end
-
- after { Puppet.settings.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")