diff options
Diffstat (limited to 'spec/unit/file_serving/metadata.rb')
| -rwxr-xr-x | spec/unit/file_serving/metadata.rb | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb index 27ebe2471..f7ab0c8d6 100755 --- a/spec/unit/file_serving/metadata.rb +++ b/spec/unit/file_serving/metadata.rb @@ -5,38 +5,16 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/metadata' describe Puppet::FileServing::Metadata do - it "should indirect file_metadata" do - Puppet::FileServing::Metadata.indirection.name.should == :file_metadata - end - - it "should should include the TerminusSelector module in its indirection" do - Puppet::FileServing::Metadata.indirection.metaclass.included_modules.should include(Puppet::FileServing::TerminusSelector) - end -end - -describe Puppet::FileServing::Metadata, " when initializing" do - it "should not allow initialization without a path" do - proc { Puppet::FileServing::Metadata.new() }.should raise_error(ArgumentError) - end - - it "should not allow the path to be fully qualified if it is provided" do - proc { Puppet::FileServing::Metadata.new("/fully/qualified") }.should raise_error(ArgumentError) + it "should should be a subclass of FileBase" do + Puppet::FileServing::Metadata.superclass.should equal(Puppet::FileServing::FileBase) end - it "should allow initialization with a relative path" do - Puppet::FileServing::Metadata.new("not/fully/qualified") - end - - it "should allow specification of whether links should be managed" do - Puppet::FileServing::Metadata.new("not/qualified", :links => :manage) - end - - it "should fail if :links is set to anything other than :manage or :follow" do - Puppet::FileServing::Metadata.new("not/qualified", :links => :manage) + it "should indirect file_metadata" do + Puppet::FileServing::Metadata.indirection.name.should == :file_metadata end - it "should default to :manage for :links" do - Puppet::FileServing::Metadata.new("not/qualified", :links => :manage) + it "should should include the IndirectionHooks module in its indirection" do + Puppet::FileServing::Metadata.indirection.metaclass.included_modules.should include(Puppet::FileServing::IndirectionHooks) end end @@ -44,9 +22,10 @@ describe Puppet::FileServing::Metadata, " when finding the file to use for setti before do @metadata = Puppet::FileServing::Metadata.new("my/path") - @base = "/base/path" @full = "/base/path/my/path" + @metadata.path = @full + # Use a symlink because it's easier to test -- no checksumming @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "symlink" end @@ -54,23 +33,22 @@ describe Puppet::FileServing::Metadata, " when finding the file to use for setti it "should accept a base path path to which the file should be relative" do File.expects(:lstat).with(@full).returns @stat File.expects(:readlink).with(@full).returns "/what/ever" - @metadata.collect_attributes(@base) + @metadata.collect_attributes end it "should use the set base path if one is not provided" do - @metadata.base_path = @base File.expects(:lstat).with(@full).returns @stat File.expects(:readlink).with(@full).returns "/what/ever" @metadata.collect_attributes() end it "should fail if a base path is neither set nor provided" do - proc { @metadata.collect_attributes() }.should raise_error(ArgumentError) + proc { @metadata.collect_attributes() }.should raise_error(Errno::ENOENT) end it "should raise an exception if the file does not exist" do - File.expects(:lstat).with("/base/dir/my/path").raises(Errno::ENOENT) - proc { @metadata.collect_attributes("/base/dir")}.should raise_error(Errno::ENOENT) + File.expects(:lstat).with(@full).raises(Errno::ENOENT) + proc { @metadata.collect_attributes()}.should raise_error(Errno::ENOENT) end end @@ -83,12 +61,8 @@ describe Puppet::FileServing::Metadata, " when collecting attributes" do @filehandle.expects(:each_line).yields("some content\n") File.stubs(:open).with(@path, 'r').yields(@filehandle) @checksum = Digest::MD5.hexdigest("some content\n") - @metadata = Puppet::FileServing::Metadata.new("file") - @metadata.collect_attributes("/my") - end - - it "should accept a file path" do - @metadata.path.should == "file" + @metadata = Puppet::FileServing::Metadata.new("file", :path => "/my/file") + @metadata.collect_attributes end # LAK:FIXME This should actually change at some point @@ -128,22 +102,22 @@ end describe Puppet::FileServing::Metadata, " when pointing to a symlink" do it "should store the destination of the symlink in :destination if links are :manage" do - file = Puppet::FileServing::Metadata.new("my/file", :links => :manage) + file = Puppet::FileServing::Metadata.new("mykey", :links => :manage, :path => "/base/path/my/file") File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755) File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" - file.collect_attributes("/base/path") + file.collect_attributes file.destination.should == "/some/other/path" end it "should not collect the checksum" do - file = Puppet::FileServing::Metadata.new("my/file", :links => :manage) + file = Puppet::FileServing::Metadata.new("my/file", :links => :manage, :path => "/base/path/my/file") File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755) File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" - file.collect_attributes("/base/path") + file.collect_attributes file.checksum.should be_nil end end |
