summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-07-05 10:21:36 +1000
committerJames Turnbull <james@lovedthanlost.net>2008-07-05 10:21:36 +1000
commit81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8 (patch)
tree192dd042cd69942d2ac803fce86e1b97eb0b3390 /spec
parent083f4ca7862fbde5cb6fb5562be10f13b66d9250 (diff)
parent9d69b3fd12f90ddead7b6a3392395fbe4e901d9b (diff)
downloadpuppet-81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8.tar.gz
puppet-81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8.tar.xz
puppet-81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8.zip
Merge branch 'refactor/0.24.x/transaction_changes' of git://github.com/lak/puppet into 0.24.x
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/other/pgraph.rb4
-rwxr-xr-xspec/unit/transaction/change.rb182
-rwxr-xr-xspec/unit/transaction/event.rb25
3 files changed, 209 insertions, 2 deletions
diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb
index 10ab934a6..cad0832a5 100755
--- a/spec/unit/other/pgraph.rb
+++ b/spec/unit/other/pgraph.rb
@@ -47,8 +47,8 @@ end
describe Puppet::PGraph, " when matching edges" do
before do
@graph = Puppet::PGraph.new
- @event = Puppet::Event.new(:source => "a", :event => :yay)
- @none = Puppet::Event.new(:source => "a", :event => :NONE)
+ @event = Puppet::Transaction::Event.new(:yay, "a")
+ @none = Puppet::Transaction::Event.new(:NONE, "a")
@edges = {}
@edges["a/b"] = Puppet::Relationship.new("a", "b", {:event => :yay, :callback => :refresh})
diff --git a/spec/unit/transaction/change.rb b/spec/unit/transaction/change.rb
new file mode 100755
index 000000000..eaa6fb4ab
--- /dev/null
+++ b/spec/unit/transaction/change.rb
@@ -0,0 +1,182 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/transaction/change'
+
+describe Puppet::Transaction::Change do
+ Change = Puppet::Transaction::Change
+
+ describe "when initializing" do
+ before do
+ @property = stub 'property', :path => "/property/path", :should => "shouldval"
+ end
+
+ it "should require the property and current value" do
+ lambda { Change.new() }.should raise_error
+ end
+
+ it "should set its property to the provided property" do
+ Change.new(@property, "value").property.should == :property
+ end
+
+ it "should set its 'is' value to the provided value" do
+ Change.new(@property, "value").is.should == "value"
+ end
+
+ it "should retrieve the 'should' value from the property" do
+ # Yay rspec :)
+ Change.new(@property, "value").should.should == @property.should
+ end
+
+ it "should set its path to the path of the property plus 'change'" do
+ Change.new(@property, "value").path.should == [@property.path, "change"]
+ end
+ end
+
+ describe "when an instance" do
+ before do
+ @property = stub 'property', :path => "/property/path", :should => "shouldval"
+ @change = Change.new(@property, "value")
+ end
+
+ it "should be noop if the property is noop" do
+ @property.expects(:noop).returns true
+ @change.noop?.should be_true
+ end
+
+ it "should set its resource to the proxy if it has one" do
+ @change.proxy = :myresource
+ @change.resource.should == :myresource
+ end
+
+ it "should set its resource to the property's resource if no proxy is set" do
+ @property.expects(:resource).returns :myresource
+ @change.resource.should == :myresource
+ end
+
+ it "should have a method for marking that it's been execution" do
+ @change.changed = true
+ @change.changed?.should be_true
+ end
+
+ describe "and creating an event" do
+ before do
+ @property.stubs(:resource).returns "myresource"
+ end
+
+ it "should produce a warning if the event name is not a symbol" do
+ @property.expects(:warning)
+ @property.stubs(:event).returns :myevent
+ @change.event("a string")
+ end
+
+ it "should use the property to generate the event name if the provided name is not a symbol" do
+ @property.stubs(:warning)
+ @property.expects(:event).with(@change.should).returns :myevent
+
+ Puppet::Transaction::Event.expects(:new).with { |name, source| name == :myevent }
+
+ @change.event("a string")
+ end
+ end
+
+ describe "and executing" do
+ describe "in noop mode" do
+ before { @change.stubs(:noop?).returns true }
+
+ it "should log that it is in noop" do
+ @property.expects(:is_to_s)
+ @property.expects(:should_to_s)
+ @property.expects(:log)
+
+ @change.stubs :event
+ @change.forward
+ end
+
+ it "should produce a :noop event and return" do
+ @property.stub_everything
+
+ @change.expects(:event).with(:noop).returns :noop_event
+
+ @change.forward.should == [:noop_event]
+ end
+ end
+
+ describe "without noop" do
+ before do
+ @change.stubs(:noop?).returns false
+ @property.stub_everything
+ @property.stubs(:resource).returns "myresource"
+ end
+
+ it "should sync the property" do
+ @property.expects(:sync)
+
+ @change.forward
+ end
+
+ it "should return nil if syncing the property returns nil" do
+ @property.stubs(:sync).returns nil
+
+ @change.forward.should be_nil
+ end
+
+ it "should return nil if syncing the property returns an empty array" do
+ @property.stubs(:sync).returns []
+
+ @change.forward.should be_nil
+ end
+
+ it "should log the change" do
+ @property.expects(:sync).returns [:one]
+
+ @property.expects(:log)
+ @property.expects(:change_to_s)
+
+ @change.forward
+ end
+
+ it "should return an array of events" do
+ @property.expects(:sync).returns [:one, :two]
+
+ @change.expects(:event).with(:one).returns :uno
+ @change.expects(:event).with(:two).returns :dos
+
+ @change.forward.should == [:uno, :dos]
+ end
+ end
+
+ describe "backward" do
+ before do
+ @property = stub 'property'
+ @property.stub_everything
+ @property.stubs(:should).returns "shouldval"
+ @change = Change.new(@property, "value")
+ @change.stubs :go
+ end
+
+ it "should swap the 'is' and 'should' values" do
+ @change.backward
+ @change.is.should == "shouldval"
+ @change.should.should == "value"
+ end
+
+ it "should set the 'should' value on the property to the previous 'is' value" do
+ @property.expects(:should=).with "value"
+ @change.backward
+ end
+
+ it "should log that it's reversing the change" do
+ @property.expects(:info)
+ @change.backward
+ end
+
+ it "should execute" do
+ @change.expects(:go)
+ @change.backward
+ end
+ end
+ end
+ end
+end
diff --git a/spec/unit/transaction/event.rb b/spec/unit/transaction/event.rb
new file mode 100755
index 000000000..9fd71aae1
--- /dev/null
+++ b/spec/unit/transaction/event.rb
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/transaction/event'
+
+describe Puppet::Transaction::Event do
+ Event = Puppet::Transaction::Event
+
+ it "should require a name and a source" do
+ lambda { Event.new }.should raise_error(ArgumentError)
+ end
+
+ it "should have a name getter" do
+ Event.new(:foo, "bar").name.should == :foo
+ end
+
+ it "should have a source accessor" do
+ Event.new(:foo, "bar").source.should == "bar"
+ end
+
+ it "should be able to produce a string containing the event name and the source" do
+ Event.new(:event, :source).to_s.should == "source -> event"
+ end
+end