diff options
| author | Luke Kanies <luke@madstop.com> | 2007-10-19 17:35:40 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-10-19 17:35:40 -0500 |
| commit | 08099b7a383987e292357f285e05933e10205660 (patch) | |
| tree | c8f08a3afca5c9b45f965c7c8d051023170ea0d5 /spec | |
| parent | ec396729d76b26d0d08c0bd633f28fa3c68c414c (diff) | |
| download | puppet-08099b7a383987e292357f285e05933e10205660.tar.gz puppet-08099b7a383987e292357f285e05933e10205660.tar.xz puppet-08099b7a383987e292357f285e05933e10205660.zip | |
File serving now works. I've tested a couple of ways to
use it, and added integration tests at the most important
hook points.
This provides the final class structure for all of these classes,
but a lot of the class names are pretty bad, so I'm planning on
going through all of them (especially the file_server stuff) and
renaming.
The functionality is all here for finding files, though (finally).
Once the classes are renamed, I'll be adding searching ability
(which will enable the recursive file copies) and then adding
the link management and enabling ignoring files.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/integration/file_serving/configuration.rb | 40 | ||||
| -rwxr-xr-x | spec/integration/indirector/module_files.rb | 26 | ||||
| -rw-r--r-- | spec/lib/shared_behaviours/file_server_mounts.rb | 16 | ||||
| -rwxr-xr-x | spec/unit/file_serving/configuration.rb | 116 | ||||
| -rwxr-xr-x | spec/unit/file_serving/mount.rb | 61 | ||||
| -rwxr-xr-x | spec/unit/file_serving/terminus_selector.rb | 22 | ||||
| -rwxr-xr-x | spec/unit/indirector/file_content/modules.rb | 18 | ||||
| -rwxr-xr-x | spec/unit/indirector/file_content/mounts.rb | 39 | ||||
| -rwxr-xr-x | spec/unit/indirector/file_metadata/modules.rb | 40 | ||||
| -rwxr-xr-x | spec/unit/indirector/file_metadata/mounts.rb | 40 | ||||
| -rwxr-xr-x | spec/unit/indirector/file_server.rb | 106 | ||||
| -rwxr-xr-x | spec/unit/indirector/module_files.rb | 96 | ||||
| -rwxr-xr-x | spec/unit/util/uri_helper.rb (renamed from spec/unit/file_serving/terminus_helper.rb) | 25 |
13 files changed, 422 insertions, 223 deletions
diff --git a/spec/integration/file_serving/configuration.rb b/spec/integration/file_serving/configuration.rb new file mode 100755 index 000000000..5af198999 --- /dev/null +++ b/spec/integration/file_serving/configuration.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-18. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/configuration' + +describe Puppet::FileServing::Configuration, " when finding files with Puppet::FileServing::Mount" do + before do + @config = Puppet::FileServing::Configuration.create + + @mount = Puppet::FileServing::Mount.new("mymount") + FileTest.stubs(:exists?).with("/my/path").returns(true) + FileTest.stubs(:readable?).with("/my/path").returns(true) + FileTest.stubs(:directory?).with("/my/path").returns(true) + @mount.path = "/my/path" + + FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true) + @parser = mock 'parser' + @parser.stubs(:parse).returns("mymount" => @mount) + @parser.stubs(:changed?).returns(true) + Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) + end + + it "should return nil if the file does not exist" do + FileTest.expects(:exists?).with("/my/path/my/file").returns(false) + @config.file_path("/mymount/my/file").should be_nil + end + + it "should return the full file path if the file exists" do + FileTest.expects(:exists?).with("/my/path/my/file").returns(true) + @config.file_path("/mymount/my/file").should == "/my/path/my/file" + end + + after do + Puppet::FileServing::Configuration.clear_cache + end +end diff --git a/spec/integration/indirector/module_files.rb b/spec/integration/indirector/module_files.rb new file mode 100755 index 000000000..67209fb39 --- /dev/null +++ b/spec/integration/indirector/module_files.rb @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-19. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/indirector/file_metadata/modules' +require 'puppet/indirector/module_files' + +describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module" do + it "should look for files in the module's 'files' directory" do + # We just test a subclass, since it's close enough. + @terminus = Puppet::Indirector::FileMetadata::Modules.new + @module = Puppet::Module.new("mymod", "/some/path/mymod") + Puppet::Module.expects(:find).with("mymod", nil).returns(@module) + + filepath = "/some/path/mymod/files/myfile" + + FileTest.expects(:exists?).with(filepath).returns(true) + + @terminus.model.expects(:new).with(filepath) + + @terminus.find("puppetmounts://host/modules/mymod/myfile") + end +end diff --git a/spec/lib/shared_behaviours/file_server_mounts.rb b/spec/lib/shared_behaviours/file_server_mounts.rb index 955f88b44..99a2f2953 100644 --- a/spec/lib/shared_behaviours/file_server_mounts.rb +++ b/spec/lib/shared_behaviours/file_server_mounts.rb @@ -23,14 +23,28 @@ describe "Puppet::Indirector::FileServerMounts", :shared => true do Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) Puppet::FileServing::Configuration.create.stubs(:modules_mount) + + # Stub out the modules terminus + @modules = mock 'modules terminus' end it "should use the file server configuration to find files" do + @modules.stubs(:find).returns(nil) + @terminus.indirection.stubs(:terminus).with(:modules).returns(@modules) + path = "/my/mount/path/my/file" FileTest.stubs(:exists?).with(path).returns(true) @test_class.expects(:new).with(path).returns(:myinstance) FileTest.stubs(:exists?).with("/my/mount/path").returns(true) - @mount1.expects(:file).with("my/file", {}).returns(path) + @mount1.expects(:file).with("my/file", :node => nil).returns(path) + + @terminus.find("puppetmounts://myhost/one/my/file").should == :myinstance + end + + it "should try to use the modules terminus to find files" do + path = "puppetmounts://myhost/one/my/file" + @modules.stubs(:find).with(path, {}).returns(:myinstance) + @terminus.indirection.stubs(:terminus).with(:modules).returns(@modules) @terminus.find("puppetmounts://myhost/one/my/file").should == :myinstance end diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb index b0b3527e7..d491447e9 100755 --- a/spec/unit/file_serving/configuration.rb +++ b/spec/unit/file_serving/configuration.rb @@ -29,6 +29,10 @@ describe Puppet::FileServing::Configuration do Puppet::FileServing::Configuration.clear_cache Puppet::FileServing::Configuration.create.should_not equal(old) end + + after do + Puppet::FileServing::Configuration.clear_cache + end end describe Puppet::FileServing::Configuration, " when initializing" do @@ -93,30 +97,6 @@ describe Puppet::FileServing::Configuration, " when parsing the configuration fi end end -describe Puppet::FileServing::Configuration, " when using a module mount" do - include FSConfigurationTesting - - before do - @parser = mock 'parser' - @parser.stubs(:changed?).returns true - FileTest.stubs(:exists?).with(@path).returns(true) - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - - @mount1 = stub 'mount', :name => "one" - @mounts = {"one" => @mount1} - - Facter.stubs(:value).with("hostname").returns("whatever") - - @config = Puppet::FileServing::Configuration.create - end - - it "should use a module mount if a module's name matches the mount name" - - it "should use any provided node name during module creation" - - it "should prefer module mounts to static mounts" -end - describe Puppet::FileServing::Configuration, " when finding files" do include FSConfigurationTesting @@ -132,7 +112,6 @@ describe Puppet::FileServing::Configuration, " when finding files" do Facter.stubs(:value).with("hostname").returns("whatever") @config = Puppet::FileServing::Configuration.create - @config.stubs(:modules_mount).returns(nil) end it "should fail if the uri does not match a leading slash followed by a valid mount name" do @@ -142,6 +121,7 @@ describe Puppet::FileServing::Configuration, " when finding files" do it "should use the first term after the first slash for the mount name" do @parser.expects(:parse).returns(@mounts) + FileTest.stubs(:exists?).returns(true) @mount1.expects(:file) @config.file_path("/one") end @@ -149,18 +129,21 @@ describe Puppet::FileServing::Configuration, " when finding files" do it "should use the remainder of the URI after the mount name as the file name" do @parser.expects(:parse).returns(@mounts) @mount1.expects(:file).with("something/else", {}) + FileTest.stubs(:exists?).returns(true) @config.file_path("/one/something/else") end it "should treat a bare name as a mount and no relative file" do @parser.expects(:parse).returns(@mounts) @mount1.expects(:file).with(nil, {}) + FileTest.stubs(:exists?).returns(true) @config.file_path("/one") end it "should treat a name with a trailing slash equivalently to a name with no trailing slash" do @parser.expects(:parse).returns(@mounts) @mount1.expects(:file).with(nil, {}) + FileTest.stubs(:exists?).returns(true) @config.file_path("/one/") end @@ -170,88 +153,27 @@ describe Puppet::FileServing::Configuration, " when finding files" do @config.file_path("/one/something").should be_nil end - it "should return nil if the mount does not contain the file" - - it "should reparse the configuration file when it has changed" do - @mount1.stubs(:file).returns("whatever") - @parser.expects(:changed?).returns(true) + it "should return nil if the mount does not contain the file" do @parser.expects(:parse).returns(@mounts) - @config.file_path("/one/something") - - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns({}) - @config.file_path("/one/something").should be_nil - end -end - -describe Puppet::FileServing::Configuration, " when finding file metadata" do - include FSConfigurationTesting - - before do - @parser = mock 'parser' - FileTest.stubs(:exists?).with(@path).returns(true) - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - - @mount1 = stub 'mount', :name => "one" - @mounts = {"one" => @mount1} - - @config = Puppet::FileServing::Configuration.create - @config.stubs(:modules_mount).returns(nil) - end - - it "should return nil if the mount cannot be found" do - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns({}) - @config.metadata("/one/something").should be_nil + @mount1.expects(:file).with("something/else", {}).returns(nil) + @config.file_path("/one/something/else").should be_nil end - it "should use the mount object to return a Metadata instance if the mount exists" do - @parser.expects(:changed?).returns(true) + it "should return the fully qualified path if the mount exists" do @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file_instance).with(:metadata, "something", {}).returns(:mydata) - @config.metadata("/one/something").should == :mydata + @mount1.expects(:file).with("something/else", {}).returns("/full/path") + @config.file_path("/one/something/else").should == "/full/path" end - it "should pass any options on to the mount" do + it "should reparse the configuration file when it has changed" do + @mount1.stubs(:file).returns("whatever") @parser.expects(:changed?).returns(true) @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file_instance).with(:metadata, "something", :node => "me").returns(:mydata) - @config.metadata("/one/something", :node => "me").should == :mydata - end -end - -describe Puppet::FileServing::Configuration, " when finding file content" do - include FSConfigurationTesting - - before do - @parser = mock 'parser' - FileTest.stubs(:exists?).with(@path).returns(true) - Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser) - - @mount1 = stub 'mount', :name => "one" - @mounts = {"one" => @mount1} - - @config = Puppet::FileServing::Configuration.create - @config.stubs(:modules_mount).returns(nil) - end + FileTest.stubs(:exists?).returns(true) + @config.file_path("/one/something") - it "should return nil if the mount cannot be found" do @parser.expects(:changed?).returns(true) @parser.expects(:parse).returns({}) - @config.content("/one/something").should be_nil - end - - it "should use the mount object to return a Content instance if the mount exists" do - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file_instance).with(:content, "something", {}).returns(:mydata) - @config.content("/one/something").should == :mydata - end - - it "should pass any options on to the mount" do - @parser.expects(:changed?).returns(true) - @parser.expects(:parse).returns(@mounts) - @mount1.expects(:file_instance).with(:content, "something", :node => "me").returns(:mydata) - @config.content("/one/something", :node => "me").should == :mydata + @config.file_path("/one/something").should be_nil end end diff --git a/spec/unit/file_serving/mount.rb b/spec/unit/file_serving/mount.rb index b646e10ca..e9a7f6ddc 100755 --- a/spec/unit/file_serving/mount.rb +++ b/spec/unit/file_serving/mount.rb @@ -3,6 +3,21 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/mount' +module FileServingMountTesting + def stub_facter(hostname) + Facter.stubs(:value).with("hostname").returns(hostname.sub(/\..+/, '')) + Facter.stubs(:value).with("domain").returns(hostname.sub(/^[^.]+\./, '')) + end +end + +describe Puppet::FileServing::Mount do + it "should provide a method for clearing its cached host information" do + Puppet::FileServing::Mount.new("whatever").send(:localmap) + Puppet::FileServing::Mount.clear_cache + Puppet::FileServing::Mount.send(:class_variable_get, "@@localmap").should be_nil + end +end + describe Puppet::FileServing::Mount, " when initializing" do it "should fail on non-alphanumeric name" do proc { Puppet::FileServing::Mount.new("non alpha") }.should raise_error(ArgumentError) @@ -23,19 +38,12 @@ describe Puppet::FileServing::Mount, " when setting the path" do @dir = "/this/path/does/not/exist" end - it "should fail if the path does not exist" do - FileTest.expects(:exists?).returns(false) - proc { @mount.path = @dir }.should raise_error(ArgumentError) - end - it "should fail if the path is not a directory" do - FileTest.expects(:exists?).returns(true) FileTest.expects(:directory?).returns(false) proc { @mount.path = @dir }.should raise_error(ArgumentError) end it "should fail if the path is not readable" do - FileTest.expects(:exists?).returns(true) FileTest.expects(:directory?).returns(true) FileTest.expects(:readable?).returns(false) proc { @mount.path = @dir }.should raise_error(ArgumentError) @@ -43,8 +51,9 @@ describe Puppet::FileServing::Mount, " when setting the path" do end describe Puppet::FileServing::Mount, " when finding files" do + include FileServingMountTesting + before do - FileTest.stubs(:exists?).returns(true) FileTest.stubs(:directory?).returns(true) FileTest.stubs(:readable?).returns(true) @mount = Puppet::FileServing::Mount.new("test") @@ -91,8 +100,7 @@ describe Puppet::FileServing::Mount, " when finding files" do end it "should use local host information if no client data is provided" do - Facter.stubs(:value).with("hostname").returns("myhost") - Facter.stubs(:value).with("domain").returns("mydomain.com") + stub_facter("myhost.mydomain.com") @mount.path = "/%h/%d/%H" @mount.path().should == "/myhost/mydomain.com/myhost.mydomain.com" end @@ -100,45 +108,40 @@ describe Puppet::FileServing::Mount, " when finding files" do it "should ignore links by default" it "should follow links when asked" + + after do + Puppet::FileServing::Mount.clear_cache + end end -describe Puppet::FileServing::Mount, " when providing file instances" do +describe Puppet::FileServing::Mount, " when providing file paths" do + include FileServingMountTesting + before do FileTest.stubs(:exists?).returns(true) FileTest.stubs(:directory?).returns(true) FileTest.stubs(:readable?).returns(true) @mount = Puppet::FileServing::Mount.new("test", "/mount/%h") + stub_facter("myhost.mydomain.com") @host = "host.domain.com" end it "should return nil if the file is absent" do - Puppet::FileServing::Metadata.expects(:new).never FileTest.stubs(:exists?).returns(false) - @mount.file_instance(:metadata, "/my/path").should be_nil + @mount.file("/my/path").should be_nil end - it "should fail if any type other than metadata or content is requested" do - proc { @mount.file_instance(:else, "/my/path") }.should raise_error(ArgumentError) + it "should return the file path if the file is absent" do + FileTest.stubs(:exists?).with("/my/path").returns(true) + @mount.file("/my/path").should == "/mount/myhost/my/path" end it "should treat a nil file name as the path to the mount itself" do - Puppet::FileServing::Metadata.expects(:new).with("/mount/myhost").returns(:myobj) FileTest.stubs(:exists?).returns(true) - @mount.file_instance(:metadata, nil).should == :myobj - end - - it "should return a Metadata instance if the file is present and metadata was asked for" do - Puppet::FileServing::Metadata.expects(:new).returns(:myobj) - @mount.file_instance(:metadata, "/my/path").should == :myobj - end - - it "should return a Content instance if the file is present and content was asked for" do - Puppet::FileServing::Content.expects(:new).returns(:myobj) - @mount.file_instance(:content, "/my/path").should == :myobj + @mount.file(nil).should == "/mount/myhost" end it "should use the client host name if provided in the options" do - Puppet::FileServing::Content.expects(:new).with("/mount/host/my/path").returns(:myobj) - @mount.file_instance(:content, "/my/path", :node => @host).should == :myobj + @mount.file("/my/path", :node => @host).should == "/mount/host/my/path" end end diff --git a/spec/unit/file_serving/terminus_selector.rb b/spec/unit/file_serving/terminus_selector.rb index d21e42839..341c60fea 100755 --- a/spec/unit/file_serving/terminus_selector.rb +++ b/spec/unit/file_serving/terminus_selector.rb @@ -30,13 +30,22 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term @object.select_terminus("puppet://host/module/file").should == :rest end - it "should choose :mounts when the protocol is 'puppetmounts'" do - @object.select_terminus("puppetmounts://host/module/file").should == :mounts + it "should choose :modules when the protocol is 'puppetmounts' and the mount name is 'modules'" do + @object.select_terminus("puppetmounts://host/modules/mymod/file").should == :modules end - it "should choose :mounts when no server name is provided and the process name is 'puppet'" do + it "should choose :modules when no server name is provided, the process name is 'puppet', and the mount name is 'modules'" do Puppet.settings.expects(:value).with(:name).returns("puppet") - @object.select_terminus("puppet:///module/file").should == :mounts + @object.select_terminus("puppet:///modules/mymod/file").should == :modules + end + + it "should choose :mounts when the protocol is 'puppetmounts' and the mount name is not 'modules'" do + @object.select_terminus("puppetmounts://host/notmodules/file").should == :mounts + end + + it "should choose :mounts when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do + Puppet.settings.expects(:value).with(:name).returns("puppet") + @object.select_terminus("puppet:///notmodules/file").should == :mounts end it "should choose :rest when no server name is provided and the process name is not 'puppet'" do @@ -52,6 +61,11 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term @object.select_terminus("/module/file").should == :local end + # This is so that we only choose modules over mounts, not local + it "should choose :local when the protocol is 'file' and the fully qualified path starts with '/modules'" do + @object.select_terminus("file://host/modules/file").should == :local + end + it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do proc { @object.select_terminus("http:///module/file") }.should raise_error(ArgumentError) end diff --git a/spec/unit/indirector/file_content/modules.rb b/spec/unit/indirector/file_content/modules.rb new file mode 100755 index 000000000..00f02bb0b --- /dev/null +++ b/spec/unit/indirector/file_content/modules.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-18. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/indirector/file_content/modules' + +describe Puppet::Indirector::FileContent::Modules do + it "should be registered with the file_content indirection" do + Puppet::Indirector::Terminus.terminus_class(:file_content, :modules).should equal(Puppet::Indirector::FileContent::Modules) + end + + it "should be a subclass of the ModuleFiles terminus" do + Puppet::Indirector::FileContent::Modules.superclass.should equal(Puppet::Indirector::ModuleFiles) + end +end diff --git a/spec/unit/indirector/file_content/mounts.rb b/spec/unit/indirector/file_content/mounts.rb index 0a137d57e..00149dfd4 100755 --- a/spec/unit/indirector/file_content/mounts.rb +++ b/spec/unit/indirector/file_content/mounts.rb @@ -12,42 +12,7 @@ describe Puppet::Indirector::FileContent::Mounts do Puppet::Indirector::Terminus.terminus_class(:file_content, :mounts).should equal(Puppet::Indirector::FileContent::Mounts) end - it "should be a subclass of the Code terminus" do - Puppet::Indirector::FileContent::Mounts.superclass.should equal(Puppet::Indirector::Code) - end -end - -describe Puppet::Indirector::FileContent::Mounts, "when finding a single file" do - before do - @content = Puppet::Indirector::FileContent::Mounts.new - @uri = "puppetmounts://host/my/local" - end - - it "should use the path portion of the URI as the file name" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local") - @content.find(@uri) - end - - it "should use the FileServing configuration to convert the file name to a fully qualified path" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local") - @content.find(@uri) - end - - it "should return nil if no fully qualified path is found" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns(nil) - @content.find(@uri).should be_nil - end - - it "should return nil if the configuration returns a file path that does not exist" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file") - FileTest.expects(:exists?).with("/some/file").returns(false) - @content.find(@uri).should be_nil - end - - it "should return a Content instance if a file is found and it exists" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file") - FileTest.expects(:exists?).with("/some/file").returns(true) - Puppet::FileServing::Content.expects(:new).with("/some/file").returns(:mycontent) - @content.find(@uri).should == :mycontent + it "should be a subclass of the FileServer terminus" do + Puppet::Indirector::FileContent::Mounts.superclass.should equal(Puppet::Indirector::FileServer) end end diff --git a/spec/unit/indirector/file_metadata/modules.rb b/spec/unit/indirector/file_metadata/modules.rb new file mode 100755 index 000000000..94e1bf0dc --- /dev/null +++ b/spec/unit/indirector/file_metadata/modules.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-18. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/indirector/file_metadata/modules' + +describe Puppet::Indirector::FileMetadata::Modules do + it "should be registered with the file_metadata indirection" do + Puppet::Indirector::Terminus.terminus_class(:file_metadata, :modules).should equal(Puppet::Indirector::FileMetadata::Modules) + end + + it "should be a subclass of the ModuleFiles terminus" do + Puppet::Indirector::FileMetadata::Modules.superclass.should equal(Puppet::Indirector::ModuleFiles) + end +end + +describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do + before do + @finder = Puppet::Indirector::FileMetadata::Modules.new + @finder.stubs(:environment).returns(nil) + @module = Puppet::Module.new("mymod", "/path/to") + @finder.stubs(:find_module).returns(@module) + end + + it "should return nil if the file is not found" do + FileTest.expects(:exists?).with("/path/to/files/my/file").returns false + @finder.find("puppetmounts://hostname/modules/mymod/my/file").should be_nil + end + + it "should retrieve the instance's attributes if the file is found" do + FileTest.expects(:exists?).with("/path/to/files/my/file").returns true + instance = mock 'metadta' + Puppet::FileServing::Metadata.expects(:new).returns instance + instance.expects :get_attributes + @finder.find("puppetmounts://hostname/modules/mymod/my/file") + end +end diff --git a/spec/unit/indirector/file_metadata/mounts.rb b/spec/unit/indirector/file_metadata/mounts.rb index 558e920ee..33f977163 100755 --- a/spec/unit/indirector/file_metadata/mounts.rb +++ b/spec/unit/indirector/file_metadata/mounts.rb @@ -12,43 +12,7 @@ describe Puppet::Indirector::FileMetadata::Mounts do Puppet::Indirector::Terminus.terminus_class(:file_metadata, :mounts).should equal(Puppet::Indirector::FileMetadata::Mounts) end - it "should be a subclass of the Code terminus" do - Puppet::Indirector::FileMetadata::Mounts.superclass.should equal(Puppet::Indirector::Code) + it "should be a subclass of the FileServer terminus" do + Puppet::Indirector::FileMetadata::Mounts.superclass.should equal(Puppet::Indirector::FileServer) end end - -describe Puppet::Indirector::FileMetadata::Mounts, "when finding a single file" do - before do - @metadata = Puppet::Indirector::FileMetadata::Mounts.new - @uri = "puppetmounts://host/my/local" - end - - it "should use the path portion of the URI as the file name" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local") - @metadata.find(@uri) - end - - it "should use the FileServing configuration to convert the file name to a fully qualified path" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local") - @metadata.find(@uri) - end - - it "should return nil if no fully qualified path is found" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns(nil) - @metadata.find(@uri).should be_nil - end - - it "should return nil if the configuration returns a file path that does not exist" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file") - FileTest.expects(:exists?).with("/some/file").returns(false) - @metadata.find(@uri).should be_nil - end - - it "should return a Metadata instance if a file is found and it exists" do - Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file") - FileTest.expects(:exists?).with("/some/file").returns(true) - Puppet::FileServing::Metadata.expects(:new).with("/some/file").returns(:mymetadata) - @metadata.find(@uri).should == :mymetadata - end -end - diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb new file mode 100755 index 000000000..5a53610e4 --- /dev/null +++ b/spec/unit/indirector/file_server.rb @@ -0,0 +1,106 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-19. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/indirector/file_server' +require 'puppet/file_serving/configuration' + +module FileServerTerminusTesting + def setup + Puppet::Indirector::Terminus.stubs(:register_terminus_class) + @model = mock 'model' + @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model + Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection) + + @file_server_class = Class.new(Puppet::Indirector::FileServer) do + def self.to_s + "Testing::Mytype" + end + end + + @file_server = @file_server_class.new + + @uri = "puppetmounts://host/my/local/file" + @configuration = mock 'configuration' + Puppet::FileServing::Configuration.stubs(:create).returns(@configuration) + + @module_server = mock 'module_server' + @indirection.stubs(:terminus).with(:modules).returns(@module_server) + end +end + +describe Puppet::Indirector::FileServer, " when finding files" do + include FileServerTerminusTesting + + it "should see if the modules terminus has the file" do + @module_server.expects(:find).with(@uri, {}) + @configuration.stubs(:file_path) + @file_server.find(@uri) + end + + it "should pass the client name to the modules terminus if one is provided" do + @module_server.expects(:find).with(@uri, :node => "mynode") + @configuration.stubs(:file_path) + @file_server.find(@uri, :node => "mynode") + end + + it "should return any results from the modules terminus" do + @module_server.expects(:find).with(@uri, {}).returns(:myinstance) + @file_server.find(@uri).should == :myinstance + end + + it "should produce a deprecation notice if it finds a file in the module terminus" do + @module_server.expects(:find).with(@uri, {}).returns(:myinstance) + Puppet.expects(:warning) + @file_server.find(@uri) + end + + it "should use the path portion of the URI as the file name" do + @configuration.expects(:file_path).with("/my/local/file", :node => nil) + @module_server.stubs(:find).returns(nil) + @file_server.find(@uri) + end + + it "should use the FileServing configuration to convert the file name to a fully qualified path" do + @configuration.expects(:file_path).with("/my/local/file", :node => nil) + @module_server.stubs(:find).returns(nil) + @file_server.find(@uri) + end + + it "should pass the node name to the FileServing configuration if one is provided" do + @configuration.expects(:file_path).with("/my/local/file", :node => "testing") + @module_server.stubs(:find) + @file_server.find(@uri, :node => "testing") + end + + it "should return nil if no fully qualified path is found" do + @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil) + @module_server.stubs(:find).returns(nil) + @file_server.find(@uri).should be_nil + end + + it "should return nil if the configuration returns a file path that does not exist" do + @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file") + FileTest.expects(:exists?).with("/some/file").returns(false) + @module_server.stubs(:find).returns(nil) + @file_server.find(@uri).should be_nil + end + + it "should return an instance of the model created with the full path if a file is found and it exists" do + @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file") + FileTest.expects(:exists?).with("/some/file").returns(true) + @module_server.stubs(:find).returns(nil) + @model.expects(:new).with("/some/file").returns(:myinstance) + @file_server.find(@uri).should == :myinstance + end +end + + +describe Puppet::Indirector::FileServer, " when returning file paths" do + it "should follow links if the links option is set to :follow" + + it "should ignore links if the links option is not set to follow" +end diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb new file mode 100755 index 000000000..2e1373748 --- /dev/null +++ b/spec/unit/indirector/module_files.rb @@ -0,0 +1,96 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-19. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/indirector/module_files' + +module ModuleFilesTerminusTesting + def setup + Puppet::Indirector::Terminus.stubs(:register_terminus_class) + @model = mock 'model' + @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model + Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection) + + @module_files_class = Class.new(Puppet::Indirector::ModuleFiles) do + def self.to_s + "Testing::Mytype" + end + end + + @module_files = @module_files_class.new + + @uri = "puppetmounts://host/modules/my/local/file" + @module = Puppet::Module.new("mymod", "/module/path") + end +end + +describe Puppet::Indirector::ModuleFiles, " when finding files" do + include ModuleFilesTerminusTesting + + it "should strip off the leading '/modules' mount name" do + Puppet::Module.expects(:find).with('my', nil).returns @module + @module_files.find(@uri) + end + + it "should not strip off leading terms that start with '/modules' but are longer words" do + Puppet::Module.expects(:find).with('modulestart', nil).returns nil + @module_files.find("puppetmounts://host/modulestart/my/local/file") + end + + it "should search for a module whose name is the first term in the remaining file path" do + Puppet::Module.expects(:find).with('my', nil).returns @module + @module_files.find(@uri) + end + + it "should search for a file relative to the module's files directory" do + Puppet::Module.expects(:find).with('my', nil).returns @module + FileTest.expects(:exists?).with("/module/path/files/local/file") + @module_files.find(@uri) + end + + it "should return nil if the module does not exist" do + Puppet::Module.expects(:find).with('my', nil).returns nil + @module_files.find(@uri).should be_nil + end + + it "should return nil if the module exists but the file does not" do + Puppet::Module.expects(:find).with('my', nil).returns @module + FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false) + @module_files.find(@uri).should be_nil + end + + it "should return an instance of the model created with the full path if a module is found and the file exists" do + Puppet::Module.expects(:find).with('my', nil).returns @module + FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) + @model.expects(:new).with("/module/path/files/local/file").returns(:myinstance) + @module_files.find(@uri).should == :myinstance + end + + it "should use the node's environment to look up the module if the node name is provided" do + node = stub "node", :environment => "testing" + Puppet::Node.expects(:find).with("mynode").returns(node) + Puppet::Module.expects(:find).with('my', "testing") + @module_files.find(@uri, :node => "mynode") + end + + it "should use the local environment setting to look up the module if the node name is not provided and the environment is not set to ''" do + Puppet.settings.stubs(:value).with(:environment).returns("testing") + Puppet::Module.expects(:find).with('my', "testing") + @module_files.find(@uri) + end + + it "should not us an environment when looking up the module if the node name is not provided and the environment is set to ''" do + Puppet.settings.stubs(:value).with(:environment).returns("") + Puppet::Module.expects(:find).with('my', nil) + @module_files.find(@uri) + end +end + +describe Puppet::Indirector::ModuleFiles, " when returning file paths" do + it "should follow links if the links option is set to :follow" + + it "should ignore links if the links option is not set to follow" +end diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/util/uri_helper.rb index f136da553..f454a2ced 100755 --- a/spec/unit/file_serving/terminus_helper.rb +++ b/spec/unit/util/uri_helper.rb @@ -5,19 +5,18 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/file_serving/terminus_helper' +require 'puppet/util/uri_helper' -module TerminusHelperTesting - def setup +describe Puppet::Util::URIHelper, " when converting a key to a URI" do + before do @helper = Object.new - @config = mock 'fs configuration' - Puppet::FileServing::Configuration.stubs(:create).returns(@config) - @helper.extend(Puppet::FileServing::TerminusHelper) + @helper.extend(Puppet::Util::URIHelper) end -end -describe Puppet::FileServing::TerminusHelper, " when converting a key to a URI" do - include TerminusHelperTesting + it "should return the URI instance" do + URI.expects(:parse).with("file:///myhost/blah").returns(:myuri) + @helper.key2uri("/myhost/blah").should == :myuri + end it "should escape the key before parsing" do URI.expects(:escape).with("mykey").returns("http://myhost/blah") @@ -40,11 +39,3 @@ describe Puppet::FileServing::TerminusHelper, " when converting a key to a URI" @helper.key2uri("/myhost/blah").should == :myuri end end - -describe Puppet::FileServing::TerminusHelper, " when returning file paths" do - include TerminusHelperTesting - - it "should follow links if the links option is set to :follow" - - it "should ignore links if the links option is not set to follow" -end |
