diff options
| author | Luke Kanies <luke@madstop.com> | 2008-11-14 19:27:50 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-11-15 02:25:47 -0600 |
| commit | 053d7bfa678b152c42bf3fcbccaaa86aa578c39b (patch) | |
| tree | 69904d2ac68767bf680b397d08ed066993e3d67d /spec/unit | |
| parent | a8d9976d0a11c4dc50b2ef49c63f3f745cb4eccb (diff) | |
| download | puppet-053d7bfa678b152c42bf3fcbccaaa86aa578c39b.tar.gz puppet-053d7bfa678b152c42bf3fcbccaaa86aa578c39b.tar.xz puppet-053d7bfa678b152c42bf3fcbccaaa86aa578c39b.zip | |
These changes are all about making sure file data is expired when appropriate.
All file tests now pass.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/node/catalog.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/type/file/ensure.rb | 75 |
2 files changed, 77 insertions, 2 deletions
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb index e23c53d3a..e3661d995 100755 --- a/spec/unit/node/catalog.rb +++ b/spec/unit/node/catalog.rb @@ -700,8 +700,8 @@ describe Puppet::Node::Catalog do @catalog.resource("File[/yay]").should be_nil end - it "should expire cached data in the resources" do - @catalog.expects(:expire) + it "should expire cached data in the resources both before and after the transaction" do + @catalog.expects(:expire).times(2) @catalog.apply end end diff --git a/spec/unit/type/file/ensure.rb b/spec/unit/type/file/ensure.rb new file mode 100755 index 000000000..be1e65110 --- /dev/null +++ b/spec/unit/type/file/ensure.rb @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +property = Puppet::Type.type(:file).attrclass(:ensure) +describe property do + before do + # Wow that's a messy interface to the resource. + @resource = stub 'resource', :[] => nil, :[]= => nil, :property => nil, :newattr => nil, :parameter => nil + end + + it "should be a subclass of Ensure" do + property.superclass.must == Puppet::Property::Ensure + end + + describe "when retrieving the current state" do + it "should return :absent if the file does not exist" do + @ensure = property.new(:resource => @resource) + @resource.expects(:stat).returns nil + + @ensure.retrieve.should == :absent + end + + it "should return the current file type if the file exists" do + @ensure = property.new(:resource => @resource) + stat = mock 'stat', :ftype => "directory" + @resource.expects(:stat).returns stat + + @ensure.retrieve.should == :directory + end + end + + describe "when testing whether :ensure is in sync" do + before do + @ensure = property.new(:resource => @resource) + @stat = stub 'stat', :ftype => "file" + end + + it "should be in sync if :ensure is set to :absent and the file does not exist" do + @ensure.should = :absent + + @ensure.must be_insync(:absent) + end + + it "should not be in sync if :ensure is set to :absent and the file exists" do + @ensure.should = :absent + + @ensure.should_not be_insync(:file) + end + + it "should be in sync if a normal file exists and :ensure is set to :present" do + @ensure.should = :present + + @ensure.must be_insync(:file) + end + + it "should be in sync if a directory exists and :ensure is set to :present" do + @ensure.should = :present + + @ensure.must be_insync(:directory) + end + + it "should be in sync if a symlink exists and :ensure is set to :present" do + @ensure.should = :present + + @ensure.must be_insync(:link) + end + + it "should not be in sync if :ensure is set to :file and a directory exists" do + @ensure.should = :file + + @ensure.should_not be_insync(:directory) + end + end +end |
