diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-04-25 20:04:59 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-04-25 20:04:59 +0000 |
| commit | 7fbd3ffe886e821a4e85e2fe9a27529133f1b84b (patch) | |
| tree | 0799d97dd7de4b55d99a1db1c7537d66948605cc /test | |
| parent | 4aaae628342debf5f964f4913a3392b641a49f20 (diff) | |
Adding the ability for parameters to declare that they require a given feature, and resources will not instantiate that parameter if required features are missing. This is mostly useful for properties.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2413 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/ral/manager/attributes.rb | 45 | ||||
| -rwxr-xr-x | test/ral/manager/provider.rb | 4 | ||||
| -rwxr-xr-x | test/ral/types/parameter.rb | 12 |
3 files changed, 61 insertions, 0 deletions
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb index 43d64f367..a23a5e9ce 100755 --- a/test/ral/manager/attributes.rb +++ b/test/ral/manager/attributes.rb @@ -244,6 +244,51 @@ class TestTypeAttributes < Test::Unit::TestCase end assert(should.empty?, "Did not get all of the parameters.") end + + # Make sure newattr handles required features correctly. + def test_newattr_and_required_features + # Make a type with some features + type = mktype + type.feature :fone, "Something" + type.feature :ftwo, "Something else" + type.newparam(:name) {} + + # Make three properties: one with no requirements, one with one, and one with two + none = type.newproperty(:none) {} + one = type.newproperty(:one, :required_features => :fone) {} + two = type.newproperty(:two, :required_features => [:fone, :ftwo]) {} + + # Now make similar providers + nope = type.provide(:nope) {} + maybe = type.provide(:maybe) { has_features :fone} + yep = type.provide(:yep) { has_features :fone, :ftwo} + + attrs = [:none, :one, :two] + + # Now make sure that we get warnings and no properties in those cases where our providers do not support the features requested + [nope, maybe, yep].each_with_index do |prov, i| + resource = type.create(:provider => prov.name, :name => "test%s" % i, :none => "a", :one => "b", :two => "c") + + case prov.name + when :nope: + yes = [:none] + no = [:one, :two] + when :maybe: + yes = [:none, :one] + no = [:two] + when :yep: + yes = [:none, :one, :two] + no = [] + end + yes.each { |a| assert(resource.should(a), "Did not get value for %s in %s" % [a, prov.name]) } + no.each do |a| + assert_nil(resource.should(a), "Got value for unsupported %s in %s" % [a, prov.name]) + assert(@logs.find { |l| l.message =~ /not managing attribute #{a}/ and l.level == :info }, "No warning about failed %s" % a) + end + + @logs.clear + end + end end # $Id$ diff --git a/test/ral/manager/provider.rb b/test/ral/manager/provider.rb index 3b727a4c5..84bb0b40c 100755 --- a/test/ral/manager/provider.rb +++ b/test/ral/manager/provider.rb @@ -115,6 +115,8 @@ class TestProviderFeatures < Test::Unit::TestCase "class missing feature %s" % feature) assert(inst.send(method), "instance missing feature %s" % feature) + assert(inst.satisfies?(feature), + "instance.satisfy %s returned false" % feature) else assert(! provider.feature?(feature), "class has feature? %s" % feature) @@ -124,6 +126,8 @@ class TestProviderFeatures < Test::Unit::TestCase "class has feature %s" % feature) assert(! inst.send(method), "instance has feature %s" % feature) + assert(! inst.satisfies?(feature), + "instance.satisfy %s returned true" % feature) end end diff --git a/test/ral/types/parameter.rb b/test/ral/types/parameter.rb index 784378f9f..b34548546 100755 --- a/test/ral/types/parameter.rb +++ b/test/ral/types/parameter.rb @@ -155,6 +155,18 @@ class TestParameter < Test::Unit::TestCase assert(obj.is_a?(Puppet::Type::Property), "alias instance is now not a property") end + + # Make sure properties can correctly require features and behave appropriately when + # those features are missing. + def test_requires_features + param = newparam(:feature_tests) + + assert_nothing_raised("could not add feature requirements to property") do + param.required_features = "testing" + end + + assert_equal([:testing], param.required_features, "required features value was not arrayfied and interned") + end end # $Id$ |
