Skip to content

Commit 610a849

Browse files
committed
Fix tests.
1 parent f8ea80c commit 610a849

2 files changed

Lines changed: 97 additions & 111 deletions

File tree

spec/classes/puppet_facts_spec.rb

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,47 +77,54 @@
7777
:clientcert => 'my.client.cert',
7878
:fqdn => 'my.fq.hostname',
7979
:environment => 'production',
80-
:puppetversion => Puppet.version
80+
:puppetversion => Puppet.version
8181
})
8282
end
8383
it { is_expected.to compile.with_all_deps }
8484
if Puppet.version.to_f >= 4.0
8585
facterbasepath = '/opt/puppetlabs/facter'
86+
facterbasepath_group = 'root'
8687
else
8788
facterbasepath = '/etc/facter'
89+
facterbasepath_group = 'puppet'
8890
end
8991
context 'when fed no parameters' do
90-
if Puppet.version.to_f >= 4.0
91-
# setting environemnt doesn't work in puppet 4
92-
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
93-
should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content(
94-
/facts for my.client.cert/
95-
).with_content(
96-
/FQDN my.fq.hostname/
97-
).with_validate_cmd(
98-
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
99-
)#.with_content(
100-
# /Environment production/
101-
#)
102-
end
103-
else
104-
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
105-
should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content(
106-
/facts for my.client.cert/
107-
).with_content(
108-
/FQDN my.fq.hostname/
109-
).with_content(
110-
/Environment production/
111-
).with_validate_cmd(
112-
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
113-
)
114-
end
92+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
93+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
94+
:path=>"#{facterbasepath}/facts.d/local.yaml",
95+
:ensure=>'file',
96+
:owner=>'root',
97+
:group=>"#{facterbasepath_group}",
98+
:mode=>'0640'
99+
}).with_content(
100+
/facts for my.client.cert/
101+
).with_content(
102+
/FQDN my.fq.hostname/
103+
).with_content(
104+
/Environment production/
105+
).with_content(
106+
/---/
107+
).with_validate_cmd(
108+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
109+
)
115110
end
116111
end#no params
117112
context 'when the custom_facts parameter is properly set key values is string' do
118-
let(:params) {{'custom_facts' => {'key1' => 'val1', 'key2' => 'val2'}}}
119-
it 'should iterate through the hash and properly populate the local_facts.yaml file' do
120-
should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content(
113+
let(:params) { {'custom_facts' => {'key1' => 'val1', 'key2' => 'val2'}} }
114+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
115+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
116+
:path=>"#{facterbasepath}/facts.d/local.yaml",
117+
:ensure=>'file',
118+
:owner=>'root',
119+
:group=>"#{facterbasepath_group}",
120+
:mode=>'0640'
121+
}).with_content(
122+
/facts for my.client.cert/
123+
).with_content(
124+
/FQDN my.fq.hostname/
125+
).with_content(
126+
/Environment production/
127+
).with_content(
121128
/---/
122129
).with_content(
123130
/key1: val1/
@@ -129,9 +136,21 @@
129136
end
130137
end#custom_facts set key values is string
131138
context 'when the custom_facts parameter is properly set key values is array' do
132-
let(:params) {{'custom_facts' => {'key1' => [ 'val11', 'val12' ], 'key2' => [ 'val21', 'val22']}}}
133-
it 'should iterate through the hash and properly populate the local_facts.yaml file' do
134-
should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content(
139+
let(:params) { {'custom_facts' => {'key1' => [ 'val11', 'val12' ], 'key2' => [ 'val21', 'val22']}} }
140+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
141+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
142+
:path=>"#{facterbasepath}/facts.d/local.yaml",
143+
:ensure=>'file',
144+
:owner=>'root',
145+
:group=>"#{facterbasepath_group}",
146+
:mode=>'0640'
147+
}).with_content(
148+
/facts for my.client.cert/
149+
).with_content(
150+
/FQDN my.fq.hostname/
151+
).with_content(
152+
/Environment production/
153+
).with_content(
135154
/---/
136155
).with_content(
137156
/key1:/
@@ -151,9 +170,21 @@
151170
end
152171
end#custom_facts set key values is array
153172
context 'when the custom_facts parameter is properly set key values is hash' do
154-
let(:params) {{'custom_facts' => {'key1' => { 'key11' => 'val11' }, 'key2' => { 'key21' => 'val21'}}}}
155-
it 'should iterate through the hash and properly populate the local_facts.yaml file' do
156-
should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content(
173+
let(:params) { {'custom_facts' => {'key1' => { 'key11' => 'val11' }, 'key2' => { 'key21' => 'val21'}}} }
174+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
175+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
176+
:path=>"#{facterbasepath}/facts.d/local.yaml",
177+
:ensure=>'file',
178+
:owner=>'root',
179+
:group=>"#{facterbasepath_group}",
180+
:mode=>'0640'
181+
}).with_content(
182+
/facts for my.client.cert/
183+
).with_content(
184+
/FQDN my.fq.hostname/
185+
).with_content(
186+
/Environment production/
187+
).with_content(
157188
/---/
158189
).with_content(
159190
/key1:/

spec/defines/fact_spec.rb

Lines changed: 31 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,6 @@
55
context 'input validation with type value is string' do
66
let (:title) { 'my_fact'}
77
let (:params) {{ 'value' => 'my_val'}}
8-
# ['path'].each do |paths|
9-
# context "when the #{paths} parameter is not an absolute path" do
10-
# let (:params) {{ paths => 'foo' }}
11-
# it 'should fail' do
12-
# expect { subject }.to raise_error(Puppet::Error, /"foo" is not an absolute path/)
13-
# end
14-
# end
15-
# end#absolute path
16-
17-
# ['array'].each do |arrays|
18-
# context "when the #{arrays} parameter is not an array" do
19-
# let (:params) {{ arrays => 'this is a string'}}
20-
# it 'should fail' do
21-
# expect { subject }.to raise_error(Puppet::Error, /is not an Array./)
22-
# end
23-
# end
24-
# end#arrays
25-
26-
# ['bool'].each do |bools|
27-
# context "when the #{bools} parameter is not an boolean" do
28-
# let (:params) {{bools => "BOGON"}}
29-
# it 'should fail' do
30-
# expect { subject }.to raise_error(Puppet::Error, /"BOGON" is not a boolean. It looks to be a String/)
31-
# end
32-
# end
33-
# end#bools
34-
35-
# ['hash'].each do |hashes|
36-
# context "when the #{hashes} parameter is not an hash" do
37-
# let (:params) {{ hashes => 'this is a string'}}
38-
# it 'should fail' do
39-
# expect { subject }.to raise_error(Puppet::Error, /is not a Hash./)
40-
# end
41-
# end
42-
# end#hashes
43-
44-
# ['string'].each do |strings|
45-
# context "when the #{strings} parameter is not a string" do
46-
# let (:params) {{strings => false }}
47-
# it 'should fail' do
48-
# expect { subject }.to raise_error(Puppet::Error, /false is not a string./)
49-
# end
50-
# end
51-
# end#strings
52-
538
end#input validation with type value is string
549

5510
context 'input validation with type value is array' do
@@ -101,19 +56,19 @@
10156
it 'should lay down our fact file as expected (value is string))' do
10257
should contain_file("#{facterbasepath}/facts.d/my_fact.yaml").with({
10358
:path=>"#{facterbasepath}/facts.d/my_fact.yaml",
104-
:ensure=>"present",
105-
:owner=>"root",
106-
:group=>"puppet",
107-
:mode=>"0640"
59+
:ensure=>'present',
60+
:owner=>'root',
61+
:group=>"#{facterbasepath_group}",
62+
:mode=>'0640'
10863
}).with_content(
109-
/# custom fact my_fact/
110-
).with_content(
111-
/---/
112-
).with_content(
113-
/my_fact: my_val/
114-
).with_validate_cmd(
115-
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
116-
)
64+
/# custom fact my_fact/
65+
).with_content(
66+
/---/
67+
).with_content(
68+
/my_fact: my_val/
69+
).with_validate_cmd(
70+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
71+
)
11772
end
11873
end
11974
context 'when fed no parameters (value is array)' do
@@ -122,10 +77,10 @@
12277
it 'should lay down our fact file as expected (value is array))' do
12378
should contain_file("#{facterbasepath}/facts.d/my_fact.yaml").with({
12479
:path=>"#{facterbasepath}/facts.d/my_fact.yaml",
125-
:ensure=>"present",
126-
:owner=>"root",
127-
:group=>"puppet",
128-
:mode=>"0640"
80+
:ensure=>'present',
81+
:owner=>'root',
82+
:group=>"#{facterbasepath_group}",
83+
:mode=>'0640'
12984
}).with_content(
13085
/# custom fact my_fact/
13186
).with_content(
@@ -147,23 +102,23 @@
147102
it 'should lay down our fact file as expected (value is hash))' do
148103
should contain_file("#{facterbasepath}/facts.d/my_fact.yaml").with({
149104
:path=>"#{facterbasepath}/facts.d/my_fact.yaml",
150-
:ensure=>"present",
151-
:owner=>"root",
105+
:ensure=>'present',
106+
:owner=>'root',
152107
:group=>"#{facterbasepath_group}",
153-
:mode=>"0640"
108+
:mode=>'0640'
154109
}).with_content(
155-
/# custom fact my_fact/
156-
).with_content(
157-
/---/
158-
).with_content(
159-
/my_fact:/
160-
).with_content(
161-
/my_key0: my_val0/
162-
).with_content(
163-
/my_key1: my_val1/
164-
).with_validate_cmd(
165-
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
166-
)
110+
/# custom fact my_fact/
111+
).with_content(
112+
/---/
113+
).with_content(
114+
/my_fact:/
115+
).with_content(
116+
/my_key0: my_val0/
117+
).with_content(
118+
/my_key1: my_val1/
119+
).with_validate_cmd(
120+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
121+
)
167122
end
168123
end
169124

0 commit comments

Comments
 (0)