rspec-puppet-facts 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +136 -13
- data/lib/rspec-puppet-facts.rb +1 -8
- data/lib/rspec-puppet-facts/version.rb +1 -1
- data/rspec-puppet-facts.gemspec +0 -1
- data/spec/rspec_puppet_facts_spec.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f41a4eb01ece38f5295c387a1fe4efb27197d5cd
|
|
4
|
+
data.tar.gz: 1296bd2cbd04897d780d4f29e84e126d9b72ee59
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e5784286b72d614a16e3aec427b0400745a5a5541cf92f02fb34d43e692d77b97d0c334493f0914345f934c978c772d4266a124abdc37b6b684d902806dee8d
|
|
7
|
+
data.tar.gz: e4713f095d37044a32ddb3a52b5b069ba94ad0b45cb91a55354ff2374104516b9267c9617502d9304b83b0aca187f4a8758a1d1b82866008c1c38fdd491668aa
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
rspec-puppet-facts
|
|
2
2
|
==================
|
|
3
3
|
|
|
4
|
-
[](https://travis-ci.org/mcanevet/rspec-puppet-facts)
|
|
5
|
+
[](https://codeclimate.com/github/mcanevet/rspec-puppet-facts)
|
|
6
|
+
[](https://rubygems.org/gems/rspec-puppet-facts)
|
|
7
|
+
[](https://rubygems.org/gems/rspec-puppet-facts)
|
|
7
8
|
[](https://coveralls.io/r/mcanevet/rspec-puppet-facts?branch=master)
|
|
8
9
|
|
|
9
10
|
Based on an original idea from [apenney](https://github.com/apenney/puppet_facts/).
|
|
10
11
|
|
|
11
12
|
Simplify your unit tests by looping on every supported Operating System and populating facts.
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
Testing a class or define
|
|
15
|
+
-------------------------
|
|
16
|
+
|
|
17
|
+
### Before
|
|
15
18
|
|
|
16
19
|
```ruby
|
|
17
20
|
require 'spec_helper'
|
|
@@ -27,7 +30,7 @@ describe 'myclass' do
|
|
|
27
30
|
...
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
it {
|
|
33
|
+
it { is_expected.to compile.with_all_deps }
|
|
31
34
|
...
|
|
32
35
|
end
|
|
33
36
|
end
|
|
@@ -41,7 +44,7 @@ describe 'myclass' do
|
|
|
41
44
|
...
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
it {
|
|
47
|
+
it { is_expected.to compile.with_all_deps }
|
|
45
48
|
...
|
|
46
49
|
end
|
|
47
50
|
end
|
|
@@ -50,8 +53,7 @@ describe 'myclass' do
|
|
|
50
53
|
end
|
|
51
54
|
```
|
|
52
55
|
|
|
53
|
-
After
|
|
54
|
-
-----
|
|
56
|
+
### After
|
|
55
57
|
|
|
56
58
|
```ruby
|
|
57
59
|
require 'spec_helper'
|
|
@@ -64,15 +66,136 @@ describe 'myclass' do
|
|
|
64
66
|
facts
|
|
65
67
|
end
|
|
66
68
|
|
|
67
|
-
it {
|
|
69
|
+
it { is_expected.to compile.with_all_deps }
|
|
70
|
+
...
|
|
71
|
+
case facts[:osfamily]
|
|
72
|
+
when 'Debian'
|
|
73
|
+
...
|
|
74
|
+
else
|
|
75
|
+
...
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Testing a type or provider
|
|
83
|
+
--------------------------
|
|
84
|
+
|
|
85
|
+
### Before
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
require 'spec_helper'
|
|
89
|
+
|
|
90
|
+
describe Puppet::Type.type(:mytype) do
|
|
91
|
+
|
|
92
|
+
context "on debian-7-x86_64" do
|
|
93
|
+
before :each do
|
|
94
|
+
Facter.clear
|
|
95
|
+
Facter.stubs(:fact).with(:osfamily).returns Facter.add(:osfamily) { setcode { 'Debian' } }
|
|
96
|
+
Facter.stubs(:fact).with(:operatingsystem).returns Facter.add(:operatingsystem) { setcode { 'Debian' } }
|
|
97
|
+
Facter.stubs(:fact).with(:operatingsystemmajrelease).returns Facter.add(:operatingsystemmajrelease) { setcode { '7' } }
|
|
98
|
+
end
|
|
99
|
+
...
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "on redhat-7-x86_64" do
|
|
103
|
+
before :each do
|
|
104
|
+
Facter.clear
|
|
105
|
+
Facter.stubs(:fact).with(:osfamily).returns Facter.add(:osfamily) { setcode { 'RedHat' } }
|
|
106
|
+
Facter.stubs(:fact).with(:operatingsystem).returns Facter.add(:operatingsystem) { setcode { 'RedHat' } }
|
|
107
|
+
Facter.stubs(:fact).with(:operatingsystemmajrelease).returns Facter.add(:operatingsystemmajrelease) { setcode { '7' } }
|
|
108
|
+
end
|
|
109
|
+
...
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### After
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
require 'spec_helper'
|
|
119
|
+
|
|
120
|
+
describe Puppet::Type.type(:mytype) do
|
|
121
|
+
|
|
122
|
+
on_supported_os.each do |os, facts|
|
|
123
|
+
context "on #{os}" do
|
|
124
|
+
before :each do
|
|
125
|
+
Facter.clear
|
|
126
|
+
facts.each do |k, v|
|
|
127
|
+
Facter.stubs(:fact).with(k).returns Facter.add(k) { setcode { v } }
|
|
128
|
+
end
|
|
129
|
+
end
|
|
68
130
|
...
|
|
69
131
|
case facts[:osfamily]
|
|
70
132
|
when 'Debian'
|
|
71
133
|
...
|
|
72
|
-
|
|
134
|
+
else
|
|
73
135
|
...
|
|
74
136
|
end
|
|
137
|
+
...
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Testing a function
|
|
145
|
+
------------------
|
|
146
|
+
|
|
147
|
+
### Before
|
|
148
|
+
|
|
149
|
+
```ruby
|
|
150
|
+
require 'spec_helper'
|
|
151
|
+
|
|
152
|
+
describe Puppet::Parser::Functions.function(:myfunction) do
|
|
153
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
|
154
|
+
|
|
155
|
+
context "on debian-7-x86_64" do
|
|
156
|
+
before :each do
|
|
157
|
+
scope.stubs(:lookupvar).with('::osfamily').returns('Debian')
|
|
158
|
+
scope.stubs(:lookupvar).with('osfamily').returns('Debian')
|
|
159
|
+
scope.stubs(:lookupvar).with('::operatingsystem').returns('Debian')
|
|
160
|
+
scope.stubs(:lookupvar).with('operatingsystem').returns('Debian')
|
|
161
|
+
...
|
|
162
|
+
end
|
|
163
|
+
...
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "on redhat-7-x86_64" do
|
|
167
|
+
before :each do
|
|
168
|
+
scope.stubs(:lookupvar).with('::osfamily').returns('RedHat')
|
|
169
|
+
scope.stubs(:lookupvar).with('osfamily').returns('RedHat')
|
|
170
|
+
scope.stubs(:lookupvar).with('::operatingsystem').returns('RedHat')
|
|
171
|
+
scope.stubs(:lookupvar).with('operatingsystem').returns('RedHat')
|
|
172
|
+
...
|
|
173
|
+
end
|
|
174
|
+
...
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### After
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
require 'spec_helper'
|
|
183
|
+
|
|
184
|
+
describe Puppet::Parser::Functions.function(:myfunction) do
|
|
185
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
|
186
|
+
|
|
187
|
+
on_supported_os.each do |os, facts|
|
|
188
|
+
context "on #{os}" do
|
|
189
|
+
before :each do
|
|
190
|
+
facts.each do |k, v|
|
|
191
|
+
scope.stubs(:lookupvar).with("::#{k}").returns(v)
|
|
192
|
+
scope.stubs(:lookupvar).with(k).returns(v)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
75
195
|
end
|
|
196
|
+
|
|
197
|
+
...
|
|
198
|
+
|
|
76
199
|
end
|
|
77
200
|
end
|
|
78
201
|
```
|
|
@@ -108,7 +231,7 @@ describe 'myclass' do
|
|
|
108
231
|
facts
|
|
109
232
|
end
|
|
110
233
|
|
|
111
|
-
it {
|
|
234
|
+
it { is_expected.to compile.with_all_deps }
|
|
112
235
|
...
|
|
113
236
|
end
|
|
114
237
|
end
|
|
@@ -130,7 +253,7 @@ describe 'myclass' do
|
|
|
130
253
|
})
|
|
131
254
|
end
|
|
132
255
|
|
|
133
|
-
it {
|
|
256
|
+
it { is_expected.to compile.with_all_deps }
|
|
134
257
|
...
|
|
135
258
|
end
|
|
136
259
|
end
|
data/lib/rspec-puppet-facts.rb
CHANGED
|
@@ -13,7 +13,7 @@ module RspecPuppetFacts
|
|
|
13
13
|
operatingsystem = os_sup['operatingsystem'].downcase
|
|
14
14
|
os_sup['operatingsystemrelease'].map do |operatingsystemmajrelease|
|
|
15
15
|
opts[:hardwaremodels].each do |hardwaremodel|
|
|
16
|
-
os = "#{operatingsystem}-#{operatingsystemmajrelease.split(
|
|
16
|
+
os = "#{operatingsystem}-#{operatingsystemmajrelease.split(/[ \.]/)[0]}-#{hardwaremodel}"
|
|
17
17
|
# TODO: use SemVer here
|
|
18
18
|
facter_minor_version = Facter.version[0..2]
|
|
19
19
|
file = File.expand_path(File.join(File.dirname(__FILE__), "../facts/#{facter_minor_version}/#{os}.facts"))
|
|
@@ -52,10 +52,3 @@ module RspecPuppetFacts
|
|
|
52
52
|
JSON.parse(File.read('metadata.json'))
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
-
|
|
56
|
-
RSpec.configure do |c|
|
|
57
|
-
begin
|
|
58
|
-
c.formatter = 'NyanCatFormatter' if Date.today.strftime('%m%d') == '0401'
|
|
59
|
-
rescue LoadError
|
|
60
|
-
end
|
|
61
|
-
end
|
data/rspec-puppet-facts.gemspec
CHANGED
|
@@ -139,5 +139,38 @@ describe 'RspecPuppetFacts' do
|
|
|
139
139
|
expect { subject }.to output(/Can't find facts for 'debian-4-x86_64'/).to_stderr
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
|
+
|
|
143
|
+
context 'When operatingsystemrelease has minor release' do
|
|
144
|
+
subject {
|
|
145
|
+
on_supported_os(
|
|
146
|
+
{
|
|
147
|
+
:supported_os => [
|
|
148
|
+
{
|
|
149
|
+
"operatingsystem" => "RedHat",
|
|
150
|
+
"operatingsystemrelease" => [
|
|
151
|
+
"5",
|
|
152
|
+
"6.5",
|
|
153
|
+
"6.6",
|
|
154
|
+
"7.1"
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
it 'should return a hash' do
|
|
162
|
+
expect(subject.class).to eq Hash
|
|
163
|
+
end
|
|
164
|
+
it 'should have 3 elements' do
|
|
165
|
+
expect(subject.size).to eq 3
|
|
166
|
+
end
|
|
167
|
+
it 'should return supported OS' do
|
|
168
|
+
expect(subject.keys.sort).to eq [
|
|
169
|
+
'redhat-5-x86_64',
|
|
170
|
+
'redhat-6-x86_64',
|
|
171
|
+
'redhat-7-x86_64',
|
|
172
|
+
]
|
|
173
|
+
end
|
|
174
|
+
end
|
|
142
175
|
end
|
|
143
176
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-puppet-facts
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mickaël Canévet
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mime-types
|