summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-20 23:59:04 -0500
committerLuke Kanies <luke@madstop.com>2008-05-20 23:59:04 -0500
commit419f2443c40116623b5c82f03eafcc85deeabcad (patch)
tree5cff2408998693744352c223743c43aa2c9c60cd /spec/unit
parent3e13bd59689a27a393c847bdbed3ac38765d79e9 (diff)
Adding support for settings within the existing Facter provider confines.
This renames the 'facter' confine to 'variable', and it prefers settings to facts. There shouldn't really be any overlap, so it shouldn't be a problem.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/provider/confine.rb4
-rwxr-xr-xspec/unit/provider/confine/variable.rb (renamed from spec/unit/provider/confine/facter.rb)50
-rwxr-xr-xspec/unit/provider/confine_collection.rb10
3 files changed, 40 insertions, 24 deletions
diff --git a/spec/unit/provider/confine.rb b/spec/unit/provider/confine.rb
index 6a9214e26..867b6e6be 100755
--- a/spec/unit/provider/confine.rb
+++ b/spec/unit/provider/confine.rb
@@ -29,8 +29,8 @@ describe Puppet::Provider::Confine do
Puppet::Provider::Confine.test(:exists).should be_instance_of(Class)
end
- it "should have a 'facter' test" do
- Puppet::Provider::Confine.test(:facter).should be_instance_of(Class)
+ it "should have a 'variable' test" do
+ Puppet::Provider::Confine.test(:variable).should be_instance_of(Class)
end
describe "when testing all values" do
diff --git a/spec/unit/provider/confine/facter.rb b/spec/unit/provider/confine/variable.rb
index 560263257..093301bdc 100755
--- a/spec/unit/provider/confine/facter.rb
+++ b/spec/unit/provider/confine/variable.rb
@@ -2,57 +2,73 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require 'puppet/provider/confine/facter'
+require 'puppet/provider/confine/variable'
-describe Puppet::Provider::Confine::Facter::Facter do
- it "should be named :facter" do
- Puppet::Provider::Confine::Facter.name.should == :facter
+describe Puppet::Provider::Confine::Variable do
+ it "should be named :variable" do
+ Puppet::Provider::Confine::Variable.name.should == :variable
end
it "should require a value" do
- lambda { Puppet::Provider::Confine::Facter.new() }.should raise_error(ArgumentError)
+ lambda { Puppet::Provider::Confine::Variable.new() }.should raise_error(ArgumentError)
end
it "should always convert values to an array" do
- Puppet::Provider::Confine::Facter.new("/some/file").values.should be_instance_of(Array)
+ Puppet::Provider::Confine::Variable.new("/some/file").values.should be_instance_of(Array)
end
- it "should have an accessor for its fact" do
- Puppet::Provider::Confine::Facter.new(:bar).should respond_to(:fact)
+ it "should have an accessor for its name" do
+ Puppet::Provider::Confine::Variable.new(:bar).should respond_to(:name)
end
describe "when testing values" do
- before { @confine = Puppet::Provider::Confine::Facter.new("foo") }
+ before do
+ @confine = Puppet::Provider::Confine::Variable.new("foo")
+ @confine.name = :myvar
+ end
+
it "should use the 'pass?' method to test validity" do
@confine.expects(:pass?).with("foo")
@confine.valid?
end
+ it "should use settings if the variable name is a valid setting" do
+ Puppet.settings.expects(:valid?).with(:myvar).returns true
+ Puppet.settings.expects(:value).with(:myvar).returns "foo"
+ @confine.pass?("foo")
+ end
+
+ it "should use Facter if the variable name is not a valid setting" do
+ Puppet.settings.expects(:valid?).with(:myvar).returns false
+ Facter.expects(:value).with(:myvar).returns "foo"
+ @confine.pass?("foo")
+ end
+
it "should return true if the value matches the facter value" do
- Facter.expects(:value).returns("foo")
+ @confine.expects(:test_value).returns "foo"
@confine.pass?("foo").should be_true
end
it "should return false if the value does not match the facter value" do
- Facter.expects(:value).returns("boo")
+ @confine.expects(:test_value).returns "fee"
@confine.pass?("foo").should be_false
end
it "should be case insensitive" do
- Facter.expects(:value).returns("FOO")
+ @confine.expects(:test_value).returns "FOO"
@confine.pass?("foo").should be_true
end
it "should not care whether the value is a string or symbol" do
- Facter.expects(:value).returns("FOO")
+ @confine.expects(:test_value).returns "FOO"
@confine.pass?(:foo).should be_true
end
- it "should cache the fact during testing" do
+ it "should cache the facter value during testing" do
Facter.expects(:value).once.returns("FOO")
@confine.pass?(:foo)
@@ -60,7 +76,7 @@ describe Puppet::Provider::Confine::Facter::Facter do
end
it "should produce a message that the fact value is not correct" do
- @confine = Puppet::Provider::Confine::Facter.new(%w{bar bee})
+ @confine = Puppet::Provider::Confine::Variable.new(%w{bar bee})
message = @confine.message("value")
message.should be_include("facter")
message.should be_include("bar,bee")
@@ -73,14 +89,14 @@ describe Puppet::Provider::Confine::Facter::Facter do
c2 = stub '2', :valid? => true, :values => %w{two}, :fact => "dos"
c3 = stub '3', :valid? => false, :values => %w{three}, :fact => "tres"
- Puppet::Provider::Confine::Facter.summarize([c1, c2, c3]).should == {"uno" => %w{one}, "tres" => %w{three}}
+ Puppet::Provider::Confine::Variable.summarize([c1, c2, c3]).should == {"uno" => %w{one}, "tres" => %w{three}}
end
it "should combine the values of multiple confines with the same fact" do
c1 = stub '1', :valid? => false, :values => %w{one}, :fact => "uno"
c2 = stub '2', :valid? => false, :values => %w{two}, :fact => "uno"
- Puppet::Provider::Confine::Facter.summarize([c1, c2]).should == {"uno" => %w{one two}}
+ Puppet::Provider::Confine::Variable.summarize([c1, c2]).should == {"uno" => %w{one two}}
end
end
end
diff --git a/spec/unit/provider/confine_collection.rb b/spec/unit/provider/confine_collection.rb
index da4b3fe72..1598b5f99 100755
--- a/spec/unit/provider/confine_collection.rb
+++ b/spec/unit/provider/confine_collection.rb
@@ -20,16 +20,16 @@ describe Puppet::Provider::ConfineCollection do
describe "and the test cannot be found" do
before do
- @facter = mock 'facter_test'
+ @variable = mock 'variable_test'
Puppet::Provider::Confine.expects(:test).with(:foo).returns nil
- Puppet::Provider::Confine.expects(:test).with(:facter).returns @facter
+ Puppet::Provider::Confine.expects(:test).with(:variable).returns @variable
end
- it "should create a Facter test with the provided values and set the fact to the test name" do
+ it "should create a Facter test with the provided values and set the name to the test name" do
confine = mock 'confine'
- confine.expects(:fact=).with(:foo)
- @facter.expects(:new).with(%w{my values}).returns confine
+ confine.expects(:name=).with(:foo)
+ @variable.expects(:new).with(%w{my values}).returns confine
Puppet::Provider::ConfineCollection.new.confine :foo => %w{my values}
end
end