blob: 7b9f53c3dff3b60c0bd74c0b5eb49da13fdf5b47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/usr/bin/env rspec
require 'spec_helper'
require 'puppet/provider/confine/variable'
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::Variable.new }.should raise_error(ArgumentError)
end
it "should always convert values to an array" do
Puppet::Provider::Confine::Variable.new("/some/file").values.should be_instance_of(Array)
end
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 do
@confine = Puppet::Provider::Confine::Variable.new("foo")
@confine.name = :myvar
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.valid?
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.valid?
end
it "should be valid if the value matches the facter value" do
@confine.expects(:test_value).returns "foo"
@confine.should be_valid
end
it "should return false if the value does not match the facter value" do
@confine.expects(:test_value).returns "fee"
@confine.should_not be_valid
end
it "should be case insensitive" do
@confine.expects(:test_value).returns "FOO"
@confine.should be_valid
end
it "should not care whether the value is a string or symbol" do
@confine.expects(:test_value).returns "FOO"
@confine.should be_valid
end
it "should produce a message that the fact value is not correct" do
@confine = Puppet::Provider::Confine::Variable.new(%w{bar bee})
@confine.name = "eh"
message = @confine.message("value")
message.should be_include("facter")
message.should be_include("bar,bee")
end
it "should be valid if the test value matches any of the provided values" do
@confine = Puppet::Provider::Confine::Variable.new(%w{bar bee})
@confine.expects(:test_value).returns "bee"
@confine.should be_valid
end
end
describe "when summarizing multiple instances" do
it "should return a hash of failing variables and their values" do
c1 = Puppet::Provider::Confine::Variable.new("one")
c1.name = "uno"
c1.expects(:valid?).returns false
c2 = Puppet::Provider::Confine::Variable.new("two")
c2.name = "dos"
c2.expects(:valid?).returns true
c3 = Puppet::Provider::Confine::Variable.new("three")
c3.name = "tres"
c3.expects(:valid?).returns false
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 = Puppet::Provider::Confine::Variable.new("one")
c1.name = "uno"
c1.expects(:valid?).returns false
c2 = Puppet::Provider::Confine::Variable.new("two")
c2.name = "uno"
c2.expects(:valid?).returns false
Puppet::Provider::Confine::Variable.summarize([c1, c2]).should == {"uno" => %w{one two}}
end
end
end
|