Skip to content

Commit cb0cb9a

Browse files
committed
Fix tests.
1 parent f8ea80c commit cb0cb9a

2 files changed

Lines changed: 99 additions & 112 deletions

File tree

spec/classes/puppet_facts_spec.rb

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,53 +71,61 @@
7171
],
7272
}).each do |os, facts|
7373
context "When on an #{os} system" do
74+
environment = Puppet::Support.environment
7475
let(:facts) do
7576
facts.merge({
7677
:concat_basedir => '/tmp',
7778
:clientcert => 'my.client.cert',
7879
:fqdn => 'my.fq.hostname',
79-
:environment => 'production',
80-
:puppetversion => Puppet.version
80+
:environment => environment,
81+
:puppetversion => Puppet.version
8182
})
8283
end
8384
it { is_expected.to compile.with_all_deps }
8485
if Puppet.version.to_f >= 4.0
8586
facterbasepath = '/opt/puppetlabs/facter'
87+
facterbasepath_group = 'root'
8688
else
8789
facterbasepath = '/etc/facter'
90+
facterbasepath_group = 'puppet'
8891
end
8992
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
93+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
94+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
95+
:path=>"#{facterbasepath}/facts.d/local.yaml",
96+
:ensure=>'file',
97+
:owner=>'root',
98+
:group=>"#{facterbasepath_group}",
99+
:mode=>'0640'
100+
}).with_content(
101+
/facts for my.client.cert/
102+
).with_content(
103+
/FQDN my.fq.hostname/
104+
).with_content(
105+
/Environment #{environment}/
106+
).with_content(
107+
/---/
108+
).with_validate_cmd(
109+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
110+
)
115111
end
116112
end#no params
117113
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(
114+
let(:params) { {'custom_facts' => {'key1' => 'val1', 'key2' => 'val2'}} }
115+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
116+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
117+
:path=>"#{facterbasepath}/facts.d/local.yaml",
118+
:ensure=>'file',
119+
:owner=>'root',
120+
:group=>"#{facterbasepath_group}",
121+
:mode=>'0640'
122+
}).with_content(
123+
/facts for my.client.cert/
124+
).with_content(
125+
/FQDN my.fq.hostname/
126+
).with_content(
127+
/Environment #{environment}/
128+
).with_content(
121129
/---/
122130
).with_content(
123131
/key1: val1/
@@ -129,9 +137,21 @@
129137
end
130138
end#custom_facts set key values is string
131139
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(
140+
let(:params) { {'custom_facts' => {'key1' => [ 'val11', 'val12' ], 'key2' => [ 'val21', 'val22']}} }
141+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
142+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
143+
:path=>"#{facterbasepath}/facts.d/local.yaml",
144+
:ensure=>'file',
145+
:owner=>'root',
146+
:group=>"#{facterbasepath_group}",
147+
:mode=>'0640'
148+
}).with_content(
149+
/facts for my.client.cert/
150+
).with_content(
151+
/FQDN my.fq.hostname/
152+
).with_content(
153+
/Environment #{environment}/
154+
).with_content(
135155
/---/
136156
).with_content(
137157
/key1:/
@@ -151,9 +171,21 @@
151171
end
152172
end#custom_facts set key values is array
153173
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(
174+
let(:params) { {'custom_facts' => {'key1' => { 'key11' => 'val11' }, 'key2' => { 'key21' => 'val21'}}} }
175+
it "should lay down #{facterbasepath}/facts.d/local.yaml" do
176+
should contain_file("#{facterbasepath}/facts.d/local.yaml").with({
177+
:path=>"#{facterbasepath}/facts.d/local.yaml",
178+
:ensure=>'file',
179+
:owner=>'root',
180+
:group=>"#{facterbasepath_group}",
181+
:mode=>'0640'
182+
}).with_content(
183+
/facts for my.client.cert/
184+
).with_content(
185+
/FQDN my.fq.hostname/
186+
).with_content(
187+
/Environment #{environment}/
188+
).with_content(
157189
/---/
158190
).with_content(
159191
/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)