summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-11 19:07:28 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-11 19:07:28 +0000
commit568501319a1ac175883afa55c2377e0c1d09dc4e (patch)
tree71ce3e79934aac4a8bb934c58e4fe8e1145401f1 /test
parent0643113a7a8127ce559aa0cce0b81df5e99d386c (diff)
downloadpuppet-568501319a1ac175883afa55c2377e0c1d09dc4e.tar.gz
puppet-568501319a1ac175883afa55c2377e0c1d09dc4e.tar.xz
puppet-568501319a1ac175883afa55c2377e0c1d09dc4e.zip
Fixing the state class so that blocks are optional for values. This is useful for cases where you want to specify values for validation but you want a method called on the provider instead.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1857 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/types/state.rb55
1 files changed, 52 insertions, 3 deletions
diff --git a/test/types/state.rb b/test/types/state.rb
index be4e8ae8c..e079c5c41 100755
--- a/test/types/state.rb
+++ b/test/types/state.rb
@@ -8,17 +8,21 @@ require 'puppettest'
class TestState < Test::Unit::TestCase
include PuppetTest
- def newinst(state)
+ def newinst(state, parent = nil)
inst = nil
+ unless parent
+ parent = "fakeparent"
+ parent.meta_def(:path) do self.to_s end
+ end
assert_nothing_raised {
- return state.new(:parent => nil)
+ return state.new(:parent => parent)
}
end
def newstate(name = :fakestate)
assert_nothing_raised {
state = Class.new(Puppet::State) do
- @name = :fakeparam
+ @name = name
end
state.initvars
@@ -124,6 +128,51 @@ class TestState < Test::Unit::TestCase
"Event did not get returned correctly")
end
+ # We want to support values with no blocks, either regexes or strings.
+ # If there's no block provided, then we should call the provider mechanism
+ # like we would normally.
+ def test_newvalue_with_no_block
+ state = newstate(:mystate)
+
+ assert_nothing_raised {
+ state.newvalue(:value, :event => :matched_value)
+ }
+ assert_nothing_raised {
+ state.newvalue(/^\d+$/, :event => :matched_number)
+ }
+
+ # Create an object that responds to mystate as an attr
+ provklass = Class.new { attr_accessor :mystate }
+ prov = provklass.new
+
+ klass = Class.new { attr_accessor :provider, :path }
+ klassinst = klass.new
+ klassinst.path = "instpath"
+ klassinst.provider = prov
+
+ inst = newinst(state, klassinst)
+
+ # Now make sure we can set the values, they get validated as normal,
+ # and they set the values on the parent rathe than trying to call
+ # a method
+ {:value => :matched_value, "27" => :matched_number}.each do |value, event|
+ assert_nothing_raised do
+ inst.should = value
+ end
+ ret = nil
+ assert_nothing_raised do
+ ret = inst.sync
+ end
+ assert_equal(event, ret, "Did not return correct event for %s" % value)
+ assert_equal(value, prov.mystate, "%s was not set right" % value)
+ end
+
+ # And make sure we still fail validations
+ assert_raise(ArgumentError) do
+ inst.should = "invalid"
+ end
+ end
+
def test_tags
obj = "yay"
metaobj = class << obj; self; end