summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2010-06-10 20:57:41 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit8f3e8bb31d513f67ea28a5f249aa850789a10ff2 (patch)
tree7bc17146f574667822b062e3e32653fe91d3c580 /spec/unit
parentd6407f46f1743b9f3916d74bc0ed521fb5bf259d (diff)
downloadpuppet-8f3e8bb31d513f67ea28a5f249aa850789a10ff2.tar.gz
puppet-8f3e8bb31d513f67ea28a5f249aa850789a10ff2.tar.xz
puppet-8f3e8bb31d513f67ea28a5f249aa850789a10ff2.zip
Working #3139 - ResourceHarness does caching
This is again about moving transactional behaviour out of Puppet::Type and into the transactional code. I initially moved this code into Resource::Status, but it seemed to make more sense in the Harness - the Status object should be thin and have no code that doesn't make sense on both sides of the pipe, it seemed. The interface gets a bit uglier as a result, but this is all about good design != good OO (because we're increasing the argument count of methods by moving them outside of the target class). Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/transaction.rb2
-rwxr-xr-xspec/unit/transaction/resource_harness.rb27
2 files changed, 22 insertions, 7 deletions
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index 0c3d901f5..c5b0ea4ec 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -316,7 +316,7 @@ describe Puppet::Transaction do
end
it "should let the resource harness determine whether the resource should be scheduled" do
- @transaction.resource_harness.expects(:scheduled?).with(@resource).returns "feh"
+ @transaction.resource_harness.expects(:scheduled?).with(@transaction.resource_status(@resource), @resource).returns "feh"
@transaction.scheduled?(@resource).should == "feh"
end
diff --git a/spec/unit/transaction/resource_harness.rb b/spec/unit/transaction/resource_harness.rb
index 334dbff77..ee2726d07 100755
--- a/spec/unit/transaction/resource_harness.rb
+++ b/spec/unit/transaction/resource_harness.rb
@@ -62,7 +62,7 @@ describe Puppet::Transaction::ResourceHarness do
changes = %w{mychanges}
@harness.stubs(:changes_to_perform).returns changes
@harness.stubs(:apply_changes)
- @resource.expects(:cache).with { |name, time| name == :synced and time.is_a?(Time) }
+ @harness.expects(:cache).with { |resource, name, time| name == :synced and time.is_a?(Time) }
@harness.evaluate(@resource)
end
@@ -110,7 +110,7 @@ describe Puppet::Transaction::ResourceHarness do
end
it "should cache that the resource was checked" do
- @resource.expects(:cache).with { |name, time| name == :checked and time.is_a?(Time) }
+ @harness.expects(:cache).with { |resource, name, time| name == :checked and time.is_a?(Time) }
@harness.changes_to_perform(@status, @resource)
end
@@ -301,21 +301,22 @@ describe Puppet::Transaction::ResourceHarness do
before do
@catalog = Puppet::Resource::Catalog.new
@resource.catalog = @catalog
+ @status = Puppet::Resource::Status.new(@resource)
end
it "should return true if 'ignoreschedules' is set" do
Puppet[:ignoreschedules] = true
@resource[:schedule] = "meh"
- @harness.should be_scheduled(@resource)
+ @harness.should be_scheduled(@status, @resource)
end
it "should return true if the resource has no schedule set" do
- @harness.should be_scheduled(@resource)
+ @harness.should be_scheduled(@status, @resource)
end
it "should return the result of matching the schedule with the cached 'checked' time if a schedule is set" do
t = Time.now
- @resource.expects(:cached).with(:checked).returns(t)
+ @harness.expects(:cached).with(@resource, :checked).returns(t)
sched = Puppet::Type.type(:schedule).new(:name => "sched")
@catalog.add_resource(sched)
@@ -323,7 +324,21 @@ describe Puppet::Transaction::ResourceHarness do
sched.expects(:match?).with(t.to_i).returns "feh"
- @harness.scheduled?(@resource).should == "feh"
+ @harness.scheduled?(@status, @resource).should == "feh"
end
end
+
+ it "should be able to cache data in the Storage module" do
+ data = {}
+ Puppet::Util::Storage.expects(:cache).with(@resource).returns data
+ @harness.cache(@resource, :foo, "something")
+
+ data[:foo].should == "something"
+ end
+
+ it "should be able to retrieve data from the cache" do
+ data = {:foo => "other"}
+ Puppet::Util::Storage.expects(:cache).with(@resource).returns data
+ @harness.cached(@resource, :foo).should == "other"
+ end
end