summaryrefslogtreecommitdiffstats
path: root/spec/unit/transaction
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2010-06-10 20:31:34 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit0b95a8528e554df07efe970c9ecfc34535d17c92 (patch)
tree42ac163a4ab9497e3fb9f676365c1b3da35c5c7d /spec/unit/transaction
parent4627b8fe11dc14bf42e98b84121b885df73c709e (diff)
Working #3139 - scheduling moved to resource harness
We previously had the schedule checking code in Puppet::Type, but it's more of a transactional function, and in order to do proper auditing in the transactional area, we need the cache checking done there. Scheduling is one of the few functions that actually uses cached data currently. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit/transaction')
-rwxr-xr-xspec/unit/transaction/resource_harness.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/unit/transaction/resource_harness.rb b/spec/unit/transaction/resource_harness.rb
index 3b9a42a38..334dbff77 100755
--- a/spec/unit/transaction/resource_harness.rb
+++ b/spec/unit/transaction/resource_harness.rb
@@ -265,4 +265,65 @@ describe Puppet::Transaction::ResourceHarness do
@harness.should_not be_allow_changes(@resource)
end
end
+
+ describe "when finding the schedule" do
+ before do
+ @catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
+ end
+
+ it "should warn and return nil if the resource has no catalog" do
+ @resource.catalog = nil
+ @resource.expects(:warning)
+
+ @harness.schedule(@resource).should be_nil
+ end
+
+ it "should return nil if the resource specifies no schedule" do
+ @harness.schedule(@resource).should be_nil
+ end
+
+ it "should fail if the named schedule cannot be found" do
+ @resource[:schedule] = "whatever"
+ @resource.expects(:fail)
+ @harness.schedule(@resource)
+ end
+
+ it "should return the named schedule if it exists" do
+ sched = Puppet::Type.type(:schedule).new(:name => "sched")
+ @catalog.add_resource(sched)
+ @resource[:schedule] = "sched"
+ @harness.schedule(@resource).to_s.should == sched.to_s
+ end
+ end
+
+ describe "when determining if a resource is scheduled" do
+ before do
+ @catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
+ end
+
+ it "should return true if 'ignoreschedules' is set" do
+ Puppet[:ignoreschedules] = true
+ @resource[:schedule] = "meh"
+ @harness.should be_scheduled(@resource)
+ end
+
+ it "should return true if the resource has no schedule set" do
+ @harness.should be_scheduled(@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)
+
+ sched = Puppet::Type.type(:schedule).new(:name => "sched")
+ @catalog.add_resource(sched)
+ @resource[:schedule] = "sched"
+
+ sched.expects(:match?).with(t.to_i).returns "feh"
+
+ @harness.scheduled?(@resource).should == "feh"
+ end
+ end
end