summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-11-11 13:12:21 -0800
committerLuke Kanies <luke@madstop.com>2008-11-11 13:12:21 -0800
commit0ecbf79faf8e69efda96f8611837cd1c395f7a7c (patch)
tree4fe918d384da032b797986c49f008548ce4e4795 /spec
parent29b97943e7efaad3cb3f8e7b82004c067d3fbf82 (diff)
downloadpuppet-0ecbf79faf8e69efda96f8611837cd1c395f7a7c.tar.gz
puppet-0ecbf79faf8e69efda96f8611837cd1c395f7a7c.tar.xz
puppet-0ecbf79faf8e69efda96f8611837cd1c395f7a7c.zip
Adding cached attribute support to resources.
The Catalog is the expirer, which means that a resource with no catalog will not cache data. Also switching files to use a cached attribute for its stat. And modifying catalogs to expire data at the end of every transaction. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/node/catalog.rb10
-rwxr-xr-xspec/unit/type.rb11
-rwxr-xr-xspec/unit/type/file.rb13
3 files changed, 24 insertions, 10 deletions
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index 28d66644a..3c4da5908 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -611,8 +611,11 @@ describe Puppet::Node::Catalog do
@transaction.stubs(:addtimes)
end
- describe "when applying" do
+ it "should be an Expirer" do
+ Puppet::Node::Catalog.ancestors.should be_include(Puppet::Util::Cacher::Expirer)
+ end
+ describe "when applying" do
it "should create and evaluate a transaction" do
@transaction.expects(:evaluate)
@catalog.apply
@@ -685,6 +688,11 @@ describe Puppet::Node::Catalog do
end
@catalog.resource("File[/yay]").should be_nil
end
+
+ it "should expire cached data in the resources" do
+ @catalog.expects(:expire)
+ @catalog.apply
+ end
end
describe "when applying host catalogs" do
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index b07f781ed..6f1052516 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -3,6 +3,17 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Puppet::Type do
+ it "should include the Cacher module" do
+ Puppet::Type.ancestors.should be_include(Puppet::Util::Cacher)
+ end
+
+ it "should use its catalog as its expirer" do
+ catalog = Puppet::Node::Catalog.new
+ resource = Puppet::Type.type(:mount).create(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
+ resource.catalog = catalog
+ resource.expirer.should equal(catalog)
+ end
+
it "should be able to retrieve a property by name" do
resource = Puppet::Type.type(:mount).create(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
resource.property(:fstype).must be_instance_of(Puppet::Type.type(:mount).attrclass(:fstype))
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index bb0fc10f3..6fd27d75b 100755
--- a/spec/unit/type/file.rb
+++ b/spec/unit/type/file.rb
@@ -164,19 +164,14 @@ describe Puppet::Type.type(:file) do
@resource.stat.should == "mystat"
end
- it "should cache the stat instance" do
+ it "should cache the stat instance if it has a catalog" do
stat = mock 'stat'
File.expects(:lstat).returns stat
- @resource.stat.should equal(@resource.stat)
- end
-
- it "should not cache nil stat values" do
- stat = mock 'stat'
- File.expects(:lstat).times(2).returns(nil).then.returns(stat)
+ catalog = Puppet::Node::Catalog.new
+ @resource.catalog = catalog
- @resource.stat.should be_nil
- @resource.stat.should equal(stat)
+ @resource.stat.should equal(@resource.stat)
end
end