rspec-puppet 2.6.4 → 2.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +32 -19
- data/lib/rspec-puppet.rb +19 -3
- data/lib/rspec-puppet/adapters.rb +35 -3
- data/lib/rspec-puppet/consts.rb +31 -0
- data/lib/rspec-puppet/monkey_patches.rb +122 -50
- data/lib/rspec-puppet/support.rb +22 -28
- data/lib/rspec-puppet/tasks/release_test.rb +144 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 306b3d94980e5582b3fdd226c2616bb15a23984d
|
4
|
+
data.tar.gz: 689b36fdc52d0e49b1eb1a587e8682949839bbd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e3a47f0994979385b56d9739feed2644fea3eea0f86568bd37fd243ce5f00f210b1d3d05c78703823396b00d881d1a0fd54de72ea180bd69a591e0d6deb62a
|
7
|
+
data.tar.gz: acc9a1cb17456547bbe4f26965856af3d76d0a8ca33be63988ada284fd08592be597a54aa667a08d5b85bb33727c4454aacd752537796971a6f1496021a2fb4d
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
All notable changes to this project will be documented in this file. This
|
3
3
|
project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [2.6.5]
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
* `derive_node_facts_from_nodename` setting added to disable the overriding of
|
10
|
+
`fqdn`, `hostname`, and `domain` facts with values derived from the node
|
11
|
+
name specified with `let(:node)`.
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
* The `trusted_facts` hash now accepts symbol keys, matching the behaviour of
|
16
|
+
the `facts` hash.
|
17
|
+
* The modifications made to Puppet internals are now contained to rspec-puppet
|
18
|
+
examples, preventing them from bleeding out into other examples in the same
|
19
|
+
RSpec process (like Ruby unit tests).
|
20
|
+
* rspec-puppet no longer attempts to configure settings for Puppet 3.x
|
21
|
+
releases that they do not support.
|
22
|
+
|
5
23
|
## [2.6.4]
|
6
24
|
|
7
25
|
### Fixed
|
data/README.md
CHANGED
@@ -99,7 +99,7 @@ A hash of default trusted facts that should be used for all the tests
|
|
99
99
|
#### trusted\_node\_data
|
100
100
|
Type | Default | Puppet Version(s)
|
101
101
|
------- | ------- | -----------------
|
102
|
-
Boolean | `false` | 3.
|
102
|
+
Boolean | `false` | >=3.4, 4.x, 5.x
|
103
103
|
|
104
104
|
Configures rspec-puppet to use the `$trusted` hash when compiling the
|
105
105
|
catalogues.
|
@@ -143,14 +143,14 @@ The search path for environment directories.
|
|
143
143
|
#### parser
|
144
144
|
Type | Default | Puppet Version(s)
|
145
145
|
------ | ----------- | -----------------
|
146
|
-
String | `"current"` | 3.
|
146
|
+
String | `"current"` | >= 3.2
|
147
147
|
|
148
148
|
This switches between the 3.x (`current`) and 4.x (`future`) parsers.
|
149
149
|
|
150
150
|
#### ordering
|
151
151
|
Type | Default | Puppet Version(s)
|
152
152
|
------ | -------------- | -----------------
|
153
|
-
String | `"title-hash"` | 3.
|
153
|
+
String | `"title-hash"` | >= 3.3, 4.x, 5.x
|
154
154
|
|
155
155
|
How unrelated resources should be ordered when applying a catalogue.
|
156
156
|
* `manifest` - Use the order in which the resources are declared in the
|
@@ -162,7 +162,7 @@ How unrelated resources should be ordered when applying a catalogue.
|
|
162
162
|
#### strict\_variables
|
163
163
|
Type | Default | Puppet Version(s)
|
164
164
|
------- | ------- | -----------------
|
165
|
-
Boolean | `false` | 3.
|
165
|
+
Boolean | `false` | >= 3.5, 4.x, 5.x
|
166
166
|
|
167
167
|
Makes Puppet raise an error when it tries to reference a variable that hasn't
|
168
168
|
been defined (not including variables that have been explicitly set to
|
@@ -171,7 +171,7 @@ been defined (not including variables that have been explicitly set to
|
|
171
171
|
#### stringify\_facts
|
172
172
|
Type | Default | Puppet Version(s)
|
173
173
|
------- | ------- | -----------------
|
174
|
-
Boolean | `true` | 3.
|
174
|
+
Boolean | `true` | >= 3.3, 4.x, 5.x
|
175
175
|
|
176
176
|
Makes rspec-puppet coerce all the fact values into strings (matching the
|
177
177
|
behaviour of older versions of Puppet).
|
@@ -194,6 +194,19 @@ Boolean | `true` | 2.x, 3.x, 4.x, 5.x
|
|
194
194
|
Configures rspec-puppet to automatically create a link from the root of your
|
195
195
|
module to `spec/fixtures/<module name>` at the beginning of the test run.
|
196
196
|
|
197
|
+
#### derive\_node\_facts\_from\_nodename
|
198
|
+
Type | Default | Puppet Version(s)
|
199
|
+
------- | ------- | -----------------
|
200
|
+
Boolean | `true` | 2.x, 3.x, 4.x, 5.x
|
201
|
+
|
202
|
+
If `true`, rspec-puppet will override the `fdqn`, `hostname`, and `domain`
|
203
|
+
facts with values that it derives from the node name (specified with
|
204
|
+
`let(:node)`.
|
205
|
+
|
206
|
+
In some circumstances (e.g. where your nodename/certname is not the same as
|
207
|
+
your FQDN), this behaviour is undesirable and can be disabled by changing this
|
208
|
+
setting to `false`.
|
209
|
+
|
197
210
|
## Naming conventions
|
198
211
|
|
199
212
|
For clarity and consistency, I recommend that you use the following directory
|
@@ -539,7 +552,7 @@ We can write the following testcase (in `spec/defines/sysctl_spec.rb`)
|
|
539
552
|
```ruby
|
540
553
|
describe 'sysctl' do
|
541
554
|
let(:title) { 'baz' }
|
542
|
-
let(:params) { {
|
555
|
+
let(:params) { { 'value' => 'foo' } }
|
543
556
|
|
544
557
|
it { is_expected.to contain_exec('sysctl/reload').with_command("/sbin/sysctl -p /etc/sysctl.conf") }
|
545
558
|
end
|
@@ -557,21 +570,21 @@ Parameters of a defined type, class or application can be passed defining `:para
|
|
557
570
|
and passing it a hash as seen below.
|
558
571
|
|
559
572
|
```ruby
|
560
|
-
let(:params) { {
|
573
|
+
let(:params) { {'ensure' => 'present', ...} }
|
561
574
|
```
|
562
575
|
|
563
576
|
For passing Puppet's `undef` as a paremeter value, you can simply use `:undef` and it will
|
564
577
|
be translated to `undef` when compiling. For example:
|
565
578
|
|
566
579
|
```ruby
|
567
|
-
let(:params) { {
|
580
|
+
let(:params) { {'user' => :undef, ...} }
|
568
581
|
```
|
569
582
|
|
570
583
|
For references to nodes or resources as seen when using `require` or `before` properties,
|
571
584
|
or an `application` resource you can pass the string as an argument to the `ref` helper:
|
572
585
|
|
573
586
|
```ruby
|
574
|
-
let(:params) {
|
587
|
+
let(:params) { 'require' => ref('Package', 'sudoku') }
|
575
588
|
```
|
576
589
|
|
577
590
|
Which translates to:
|
@@ -583,7 +596,7 @@ mydefine { 'mytitle': require => Package['sudoku'] }
|
|
583
596
|
Another example, for an application setup (when using `app_management`):
|
584
597
|
|
585
598
|
```ruby
|
586
|
-
let(:params) { {
|
599
|
+
let(:params) { { 'nodes' => { ref('Node', 'dbnode') => ref('Myapp::Mycomponent', 'myapp') } } }
|
587
600
|
```
|
588
601
|
|
589
602
|
Will translate to:
|
@@ -616,7 +629,7 @@ By default, the test environment contains no facts for your manifest to use.
|
|
616
629
|
You can set them with a hash
|
617
630
|
|
618
631
|
```ruby
|
619
|
-
let(:facts) { {
|
632
|
+
let(:facts) { {'operatingsystem' => 'Debian', 'kernel' => 'Linux', ...} }
|
620
633
|
```
|
621
634
|
|
622
635
|
Facts may be expressed as a value (shown in the previous example) or a structure. Fact keys
|
@@ -624,7 +637,7 @@ may be expressed as either symbols or strings. A key will be converted to a low
|
|
624
637
|
string to align with the Facter standard
|
625
638
|
|
626
639
|
```ruby
|
627
|
-
let(:facts) { {
|
640
|
+
let(:facts) { {'os' => { 'family' => 'RedHat', 'release' => { 'major' => '7', 'minor' => '1', 'full' => '7.1.1503' } } } }
|
628
641
|
```
|
629
642
|
|
630
643
|
You can also create a set of default facts provided to all specs in your spec_helper:
|
@@ -632,7 +645,7 @@ You can also create a set of default facts provided to all specs in your spec_he
|
|
632
645
|
``` ruby
|
633
646
|
RSpec.configure do |c|
|
634
647
|
c.default_facts = {
|
635
|
-
|
648
|
+
'operatingsystem' => 'Ubuntu'
|
636
649
|
}
|
637
650
|
end
|
638
651
|
```
|
@@ -646,7 +659,7 @@ You can create top-scope variables much in the same way as an ENC.
|
|
646
659
|
|
647
660
|
|
648
661
|
```ruby
|
649
|
-
let(:node_params) { {
|
662
|
+
let(:node_params) { { 'hostgroup' => 'webservers', 'rack' => 'KK04', 'status' => 'maintenance' } }
|
650
663
|
```
|
651
664
|
|
652
665
|
You can also create a set of default top-scope variables provided to all specs in your spec_helper:
|
@@ -654,9 +667,9 @@ You can also create a set of default top-scope variables provided to all specs i
|
|
654
667
|
``` ruby
|
655
668
|
RSpec.configure do |c|
|
656
669
|
c.default_node_params = {
|
657
|
-
|
658
|
-
|
659
|
-
|
670
|
+
'owner' => 'itprod',
|
671
|
+
'site' => 'ams4',
|
672
|
+
'status' => 'live'
|
660
673
|
}
|
661
674
|
end
|
662
675
|
```
|
@@ -773,7 +786,7 @@ describe 'orch_app' do
|
|
773
786
|
let(:title) { 'my_awesome_app' }
|
774
787
|
let(:params) do
|
775
788
|
{
|
776
|
-
|
789
|
+
'nodes' => {
|
777
790
|
ref('Node', node) => ref('Orch_app::Db', title),
|
778
791
|
}
|
779
792
|
}
|
@@ -965,7 +978,7 @@ user:
|
|
965
978
|
|
966
979
|
```ruby
|
967
980
|
ntpserver = hiera.lookup('ntpserver', nil, nil)
|
968
|
-
let(:params) {
|
981
|
+
let(:params) { 'ntpserver' => ntpserver }
|
969
982
|
```
|
970
983
|
|
971
984
|
### Enabling hiera lookups
|
data/lib/rspec-puppet.rb
CHANGED
@@ -8,6 +8,7 @@ require 'rspec-puppet/example'
|
|
8
8
|
require 'rspec-puppet/setup'
|
9
9
|
require 'rspec-puppet/coverage'
|
10
10
|
require 'rspec-puppet/adapters'
|
11
|
+
require 'rspec-puppet/consts'
|
11
12
|
|
12
13
|
begin
|
13
14
|
require 'puppet/test/test_helper'
|
@@ -18,6 +19,12 @@ RSpec.configure do |c|
|
|
18
19
|
c.add_setting :enable_pathname_stubbing, :default => false
|
19
20
|
end
|
20
21
|
|
22
|
+
module RSpec::Puppet
|
23
|
+
def self.rspec_puppet_example?
|
24
|
+
RSpec::Puppet::EventListener.rspec_puppet_example?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
21
28
|
require 'rspec-puppet/monkey_patches'
|
22
29
|
|
23
30
|
RSpec.configure do |c|
|
@@ -37,8 +44,10 @@ RSpec.configure do |c|
|
|
37
44
|
c.add_setting :ordering, :default => 'title-hash'
|
38
45
|
c.add_setting :stringify_facts, :default => true
|
39
46
|
c.add_setting :strict_variables, :default => false
|
40
|
-
c.add_setting :adapter
|
41
47
|
c.add_setting :setup_fixtures, :default => true
|
48
|
+
c.add_setting :derive_node_facts_from_nodename, :default => true
|
49
|
+
c.add_setting :adapter
|
50
|
+
c.add_setting :platform, :default => Puppet::Util::Platform.actual_platform
|
42
51
|
|
43
52
|
c.before(:all) do
|
44
53
|
if RSpec.configuration.setup_fixtures?
|
@@ -85,7 +94,7 @@ RSpec.configure do |c|
|
|
85
94
|
end
|
86
95
|
|
87
96
|
c.before :each do
|
88
|
-
if
|
97
|
+
if RSpec::Puppet.rspec_puppet_example?
|
89
98
|
@adapter = RSpec::Puppet::Adapters.get
|
90
99
|
@adapter.setup_puppet(self)
|
91
100
|
c.adapter = adapter
|
@@ -93,6 +102,13 @@ RSpec.configure do |c|
|
|
93
102
|
end
|
94
103
|
|
95
104
|
c.before :each do |example|
|
96
|
-
|
105
|
+
if RSpec::Puppet.rspec_puppet_example?
|
106
|
+
Puppet::Util::Platform.pretend_to_be RSpec.configuration.platform
|
107
|
+
stub_file_consts(example) if self.respond_to?(:stub_file_consts)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
c.after(:each) do
|
112
|
+
RSpec::Puppet::Consts.restore_consts if RSpec::Puppet.rspec_puppet_example?
|
97
113
|
end
|
98
114
|
end
|
@@ -183,17 +183,45 @@ module RSpec::Puppet
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
class
|
186
|
+
class Adapter30 < Base
|
187
187
|
def settings_map
|
188
188
|
super.concat([
|
189
189
|
[:manifestdir, :manifest_dir],
|
190
190
|
[:manifest, :manifest],
|
191
191
|
[:templatedir, :template_dir],
|
192
192
|
[:hiera_config, :hiera_config],
|
193
|
+
])
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
class Adapter32 < Adapter30
|
198
|
+
def settings_map
|
199
|
+
super.concat([
|
193
200
|
[:parser, :parser],
|
194
|
-
|
201
|
+
])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class Adapter33 < Adapter32
|
206
|
+
def settings_map
|
207
|
+
super.concat([
|
195
208
|
[:ordering, :ordering],
|
196
209
|
[:stringify_facts, :stringify_facts],
|
210
|
+
])
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
class Adapter34 < Adapter33
|
215
|
+
def settings_map
|
216
|
+
super.concat([
|
217
|
+
[:trusted_node_data, :trusted_node_data],
|
218
|
+
])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
class Adapter35 < Adapter34
|
223
|
+
def settings_map
|
224
|
+
super.concat([
|
197
225
|
[:strict_variables, :strict_variables],
|
198
226
|
])
|
199
227
|
end
|
@@ -212,7 +240,11 @@ module RSpec::Puppet
|
|
212
240
|
def self.get
|
213
241
|
[
|
214
242
|
['4.0', Adapter4X],
|
215
|
-
['3.
|
243
|
+
['3.5', Adapter35],
|
244
|
+
['3.4', Adapter34],
|
245
|
+
['3.3', Adapter33],
|
246
|
+
['3.2', Adapter32],
|
247
|
+
['3.0', Adapter30],
|
216
248
|
['2.7', Adapter27]
|
217
249
|
].each do |(version, klass)|
|
218
250
|
if Puppet::Util::Package.versioncmp(Puppet.version, version) >= 0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RSpec::Puppet::Consts
|
2
|
+
STUBBED_CONSTS = {
|
3
|
+
:posix => {
|
4
|
+
'File::PATH_SEPARATOR' => ':',
|
5
|
+
'File::ALT_SEPARATOR' => nil,
|
6
|
+
'Pathname::SEPARATOR_PAT' => /#{Regexp.quote('/')}/,
|
7
|
+
},
|
8
|
+
:windows => {
|
9
|
+
'File::PATH_SEPARATOR' => ';',
|
10
|
+
'File::ALT_SEPARATOR' => "\\",
|
11
|
+
'Pathname::SEPARATOR_PAT' => /[#{Regexp.quote("\\")}#{Regexp.quote('/')}]/,
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.stub_consts_for(platform)
|
16
|
+
STUBBED_CONSTS[platform].each do |const_name, const_value|
|
17
|
+
stub_const_wrapper(const_name, const_value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.stub_const_wrapper(const, value)
|
22
|
+
klass_name, const_name = const.split('::', 2)
|
23
|
+
klass = Object.const_get(klass_name)
|
24
|
+
klass.send(:remove_const, const_name) if klass.const_defined?(const_name)
|
25
|
+
klass.const_set(const_name, value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.restore_consts
|
29
|
+
stub_consts_for(RSpec.configuration.platform)
|
30
|
+
end
|
31
|
+
end
|
@@ -1,5 +1,29 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
+
class RSpec::Puppet::EventListener
|
4
|
+
def self.example_started(example)
|
5
|
+
if rspec3?
|
6
|
+
@rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support)
|
7
|
+
else
|
8
|
+
@rspec_puppet_example = example.example_group.ancestors.include?(RSpec::Puppet::Support)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.rspec_puppet_example?
|
13
|
+
@rspec_puppet_example || false
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.rspec3?
|
17
|
+
if @rspec3.nil?
|
18
|
+
@rspec3 = defined?(RSpec::Core::Notifications)
|
19
|
+
end
|
20
|
+
|
21
|
+
@rspec3
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec.configuration.reporter.register_listener(RSpec::Puppet::EventListener, :example_started)
|
26
|
+
|
3
27
|
module Puppet
|
4
28
|
# Allow rspec-puppet to prevent Puppet::Type from automatically picking
|
5
29
|
# a provider for a resource. We need to do this because in order to fully
|
@@ -11,32 +35,36 @@ module Puppet
|
|
11
35
|
old_set_default = instance_method(:set_default)
|
12
36
|
|
13
37
|
define_method(:set_default) do |attr|
|
14
|
-
|
15
|
-
|
38
|
+
if RSpec::Puppet.rspec_puppet_example?
|
39
|
+
old_posix = nil
|
40
|
+
old_microsoft_windows = nil
|
41
|
+
|
42
|
+
if attr == :provider
|
43
|
+
old_posix = Puppet.features.posix?
|
44
|
+
old_microsoft_windows = Puppet.features.microsoft_windows?
|
45
|
+
|
46
|
+
if Puppet::Util::Platform.pretend_windows?
|
47
|
+
Puppet.features.add(:posix) { false }
|
48
|
+
Puppet.features.add(:microsoft_windows) { true }
|
49
|
+
else
|
50
|
+
Puppet.features.add(:posix) { true }
|
51
|
+
Puppet.features.add(:microsoft_windows) { false }
|
52
|
+
end
|
53
|
+
end
|
16
54
|
|
17
|
-
|
18
|
-
old_posix = Puppet.features.posix?
|
19
|
-
old_microsoft_windows = Puppet.features.microsoft_windows?
|
55
|
+
retval = old_set_default.bind(self).call(attr)
|
20
56
|
|
21
|
-
|
22
|
-
Puppet.features.add(:posix) {
|
23
|
-
|
24
|
-
|
25
|
-
Puppet.features.add(:
|
26
|
-
Puppet.features.add(:microsoft_windows) { false }
|
57
|
+
unless old_posix.nil?
|
58
|
+
Puppet.features.add(:posix) { old_posix }
|
59
|
+
end
|
60
|
+
unless old_microsoft_windows.nil?
|
61
|
+
Puppet.features.add(:microsoft_windows) { old_microsoft_windows }
|
27
62
|
end
|
28
|
-
end
|
29
|
-
|
30
|
-
retval = old_set_default.bind(self).call(attr)
|
31
63
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
unless old_microsoft_windows.nil?
|
36
|
-
Puppet.features.add(:microsoft_windows) { old_microsoft_windows }
|
64
|
+
retval
|
65
|
+
else
|
66
|
+
old_set_default.bind(self).call(attr)
|
37
67
|
end
|
38
|
-
|
39
|
-
retval
|
40
68
|
end
|
41
69
|
|
42
70
|
def self.suppress_provider?
|
@@ -52,37 +80,47 @@ module Puppet
|
|
52
80
|
end
|
53
81
|
end
|
54
82
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
class Node::Environment
|
62
|
-
if instance_methods.include?("validate_dirs")
|
63
|
-
old_validate_dirs = instance_method(:validate_dirs)
|
64
|
-
|
65
|
-
define_method(:validate_dirs) do |dirs|
|
83
|
+
module Parser::Files
|
84
|
+
alias :old_find_manifests_in_modules :find_manifests_in_modules
|
85
|
+
module_function :old_find_manifests_in_modules
|
86
|
+
|
87
|
+
def find_manifests_in_modules(pattern, environment)
|
88
|
+
if RSpec::Puppet.rspec_puppet_example?
|
66
89
|
pretending = Puppet::Util::Platform.pretend_platform
|
67
90
|
|
68
|
-
|
91
|
+
unless pretending.nil?
|
69
92
|
Puppet::Util::Platform.pretend_to_be nil
|
93
|
+
RSpec::Puppet::Consts.stub_consts_for(RSpec.configuration.platform)
|
70
94
|
end
|
71
95
|
|
72
|
-
|
96
|
+
environment.send(:value_cache).clear if environment.respond_to?(:value_cache, true)
|
97
|
+
output = old_find_manifests_in_modules(pattern, environment)
|
73
98
|
|
74
|
-
|
99
|
+
unless pretending.nil?
|
100
|
+
Puppet::Util::Platform.pretend_to_be pretending
|
101
|
+
RSpec::Puppet::Consts.stub_consts_for pretending
|
102
|
+
end
|
75
103
|
|
76
104
|
output
|
105
|
+
else
|
106
|
+
old_find_manifests_in_modules(pattern, environment)
|
77
107
|
end
|
78
108
|
end
|
109
|
+
module_function :find_manifests_in_modules
|
79
110
|
end
|
80
111
|
|
81
112
|
module Util
|
82
113
|
# Allow rspec-puppet to pretend to be different platforms.
|
83
114
|
module Platform
|
115
|
+
alias :old_windows? :windows?
|
116
|
+
module_function :old_windows?
|
117
|
+
|
84
118
|
def windows?
|
85
|
-
|
119
|
+
if RSpec::Puppet.rspec_puppet_example?
|
120
|
+
pretend_platform.nil? ? (actual_platform == :windows) : pretend_windows?
|
121
|
+
else
|
122
|
+
old_windows?
|
123
|
+
end
|
86
124
|
end
|
87
125
|
module_function :windows?
|
88
126
|
|
@@ -112,16 +150,32 @@ module Puppet
|
|
112
150
|
end
|
113
151
|
end
|
114
152
|
|
115
|
-
|
153
|
+
begin
|
154
|
+
require 'puppet/confine/exists'
|
155
|
+
|
116
156
|
class Confine::Exists < Puppet::Confine
|
117
|
-
|
118
|
-
|
157
|
+
old_pass = instance_method(:pass?)
|
158
|
+
|
159
|
+
define_method(:pass?) do |value|
|
160
|
+
if RSpec::Puppet.rspec_puppet_example?
|
161
|
+
true
|
162
|
+
else
|
163
|
+
old_pass.bind(self).call(value)
|
164
|
+
end
|
119
165
|
end
|
120
166
|
end
|
121
|
-
|
167
|
+
rescue LoadError
|
168
|
+
require 'puppet/provider/confine/exists'
|
169
|
+
|
122
170
|
class Provider::Confine::Exists < Puppet::Provider::Confine
|
123
|
-
|
124
|
-
|
171
|
+
old_pass = instance_method(:pass?)
|
172
|
+
|
173
|
+
define_method(:pass?) do |value|
|
174
|
+
if RSpec::Puppet.rspec_puppet_example?
|
175
|
+
true
|
176
|
+
else
|
177
|
+
old_pass.bind(self).call(value)
|
178
|
+
end
|
125
179
|
end
|
126
180
|
end
|
127
181
|
end
|
@@ -141,12 +195,16 @@ class Pathname
|
|
141
195
|
old_chop_basename = instance_method(:chop_basename)
|
142
196
|
|
143
197
|
define_method(:chop_basename) do |path|
|
144
|
-
if RSpec.
|
145
|
-
|
146
|
-
|
147
|
-
|
198
|
+
if RSpec::Puppet.rspec_puppet_example?
|
199
|
+
if RSpec.configuration.enable_pathname_stubbing
|
200
|
+
base = rspec_puppet_basename(path)
|
201
|
+
if /\A#{SEPARATOR_PAT}?\z/o =~ base
|
202
|
+
return nil
|
203
|
+
else
|
204
|
+
return path[0, path.rindex(base)], base
|
205
|
+
end
|
148
206
|
else
|
149
|
-
|
207
|
+
old_chop_basename.bind(self).call(path)
|
150
208
|
end
|
151
209
|
else
|
152
210
|
old_chop_basename.bind(self).call(path)
|
@@ -157,12 +215,26 @@ end
|
|
157
215
|
|
158
216
|
# Prevent the File type from munging paths (which uses File.expand_path to
|
159
217
|
# normalise paths, which does very bad things to *nix paths on Windows.
|
160
|
-
Puppet::Type.type(:file).paramclass(:path).
|
218
|
+
file_path_munge = Puppet::Type.type(:file).paramclass(:path).instance_method(:unsafe_munge)
|
219
|
+
Puppet::Type.type(:file).paramclass(:path).munge do |value|
|
220
|
+
if RSpec::Puppet.rspec_puppet_example?
|
221
|
+
value
|
222
|
+
else
|
223
|
+
file_path_munge.bind(self).call(value)
|
224
|
+
end
|
225
|
+
end
|
161
226
|
|
162
227
|
# Prevent the Exec type from validating the user. This parameter isn't
|
163
228
|
# supported under Windows at all and only under *nix when the current user is
|
164
229
|
# root.
|
165
|
-
Puppet::Type.type(:exec).paramclass(:user).
|
230
|
+
exec_user_validate = Puppet::Type.type(:exec).paramclass(:user).instance_method(:unsafe_validate)
|
231
|
+
Puppet::Type.type(:exec).paramclass(:user).validate do |value|
|
232
|
+
if RSpec::Puppet.rspec_puppet_example?
|
233
|
+
true
|
234
|
+
else
|
235
|
+
exec_user_validate.bind(self).call(value)
|
236
|
+
end
|
237
|
+
end
|
166
238
|
|
167
239
|
# Prevent Puppet from requiring 'puppet/util/windows' if we're pretending to be
|
168
240
|
# windows, otherwise it will require other libraries that probably won't be
|
@@ -170,7 +242,7 @@ Puppet::Type.type(:exec).paramclass(:user).validate { |value| true }
|
|
170
242
|
module Kernel
|
171
243
|
alias :old_require :require
|
172
244
|
def require(path)
|
173
|
-
return if path == 'puppet/util/windows' && Puppet::Util::Platform.pretend_windows?
|
245
|
+
return if path == 'puppet/util/windows' && RSpec::Puppet.rspec_puppet_example? && Puppet::Util::Platform.pretend_windows?
|
174
246
|
old_require(path)
|
175
247
|
end
|
176
248
|
end
|
data/lib/rspec-puppet/support.rb
CHANGED
@@ -4,7 +4,6 @@ require 'rspec-puppet/raw_string'
|
|
4
4
|
|
5
5
|
module RSpec::Puppet
|
6
6
|
module Support
|
7
|
-
|
8
7
|
@@cache = RSpec::Puppet::Cache.new
|
9
8
|
|
10
9
|
def subject
|
@@ -55,25 +54,14 @@ module RSpec::Puppet
|
|
55
54
|
|
56
55
|
munged_facts = facts_hash(nodename(type))
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def stub_const_wrapper(const, value)
|
70
|
-
if defined?(RSpec::Core::MockingAdapters::RSpec) && RSpec.configuration.mock_framework == RSpec::Core::MockingAdapters::RSpec
|
71
|
-
stub_const(const, value)
|
72
|
-
else
|
73
|
-
klass_name, const_name = const.split('::', 2)
|
74
|
-
klass = Object.const_get(klass_name)
|
75
|
-
klass.send(:remove_const, const_name) if klass.const_defined?(const_name)
|
76
|
-
klass.const_set(const_name, value)
|
57
|
+
['operatingsystem', 'osfamily'].each do |os_fact|
|
58
|
+
if munged_facts.key?(os_fact)
|
59
|
+
if munged_facts[os_fact].to_s.downcase == 'windows'
|
60
|
+
RSpec::Puppet::Consts.stub_consts_for(:windows)
|
61
|
+
else
|
62
|
+
RSpec::Puppet::Consts.stub_consts_for(:posix)
|
63
|
+
end
|
64
|
+
end
|
77
65
|
end
|
78
66
|
end
|
79
67
|
|
@@ -239,7 +227,7 @@ module RSpec::Puppet
|
|
239
227
|
|
240
228
|
# Merge node facts again on top of `let(:facts)` facts, but only if
|
241
229
|
# a node name is given with `let(:node)`
|
242
|
-
if respond_to?(:node)
|
230
|
+
if respond_to?(:node) && RSpec.configuration.derive_node_facts_from_nodename
|
243
231
|
result_facts.merge!(munge_facts(node_facts))
|
244
232
|
(result_facts['networking'] ||= {}).merge!(networking_facts)
|
245
233
|
end
|
@@ -269,10 +257,10 @@ module RSpec::Puppet
|
|
269
257
|
extensions = {}
|
270
258
|
|
271
259
|
if RSpec.configuration.default_trusted_facts.any?
|
272
|
-
extensions.merge!(RSpec.configuration.default_trusted_facts)
|
260
|
+
extensions.merge!(munge_facts(RSpec.configuration.default_trusted_facts))
|
273
261
|
end
|
274
262
|
|
275
|
-
extensions.merge!(trusted_facts) if self.respond_to?(:trusted_facts)
|
263
|
+
extensions.merge!(munge_facts(trusted_facts)) if self.respond_to?(:trusted_facts)
|
276
264
|
extensions
|
277
265
|
end
|
278
266
|
|
@@ -367,16 +355,22 @@ module RSpec::Puppet
|
|
367
355
|
end
|
368
356
|
|
369
357
|
def stub_facts!(facts)
|
370
|
-
if facts['operatingsystem'] && facts['operatingsystem'].to_s.downcase == 'windows'
|
371
|
-
Puppet::Util::Platform.pretend_to_be :windows
|
372
|
-
else
|
373
|
-
Puppet::Util::Platform.pretend_to_be :posix
|
374
|
-
end
|
375
358
|
Puppet.settings[:autosign] = false
|
376
359
|
facts.each { |k, v| Facter.add(k) { setcode { v } } }
|
377
360
|
end
|
378
361
|
|
379
362
|
def build_catalog(*args)
|
363
|
+
build_facts = args[1]
|
364
|
+
['operatingsystem', 'osfamily'].each do |os_fact|
|
365
|
+
if build_facts.key?(os_fact)
|
366
|
+
if build_facts[os_fact].to_s.downcase == 'windows'
|
367
|
+
Puppet::Util::Platform.pretend_to_be :windows
|
368
|
+
else
|
369
|
+
Puppet::Util::Platform.pretend_to_be :posix
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
380
374
|
@@cache.get(*args) do |*args|
|
381
375
|
build_catalog_without_cache(*args)
|
382
376
|
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'open3'
|
3
|
+
require 'json'
|
4
|
+
require 'parser/current'
|
5
|
+
|
6
|
+
task :release_test do
|
7
|
+
modules_to_test = [
|
8
|
+
'puppetlabs/puppetlabs-apt',
|
9
|
+
'puppetlabs/puppetlabs-tomcat',
|
10
|
+
'puppetlabs/puppetlabs-apache',
|
11
|
+
'puppetlabs/puppetlabs-mysql',
|
12
|
+
'puppetlabs/puppetlabs-ntp',
|
13
|
+
'puppetlabs/puppetlabs-acl',
|
14
|
+
'puppetlabs/puppetlabs-chocolatey',
|
15
|
+
'voxpupuli/puppet-archive',
|
16
|
+
'voxpupuli/puppet-collectd',
|
17
|
+
'garethr/garethr-docker',
|
18
|
+
'sensu/sensu-puppet',
|
19
|
+
'jenkinsci/puppet-jenkins',
|
20
|
+
]
|
21
|
+
|
22
|
+
Bundler.with_clean_env do
|
23
|
+
FileUtils.mkdir_p('tmp')
|
24
|
+
Dir.chdir('tmp') do
|
25
|
+
modules_to_test.each do |module_name|
|
26
|
+
puts "Testing #{module_name}..."
|
27
|
+
module_dir = File.basename(module_name)
|
28
|
+
|
29
|
+
if File.directory?(module_dir)
|
30
|
+
Dir.chdir(module_dir) do
|
31
|
+
print ' Updating repository... '
|
32
|
+
_, status = Open3.capture2e('git', 'pull', '--rebase')
|
33
|
+
if status.success?
|
34
|
+
puts 'Done'
|
35
|
+
else
|
36
|
+
puts 'FAILED'
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
print ' Cloning repository... '
|
42
|
+
_, status = Open3.capture2e('git', 'clone', "https://github.com/#{module_name}")
|
43
|
+
if status.success?
|
44
|
+
puts 'Done'
|
45
|
+
else
|
46
|
+
puts 'FAILED'
|
47
|
+
next
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Dir.chdir(module_dir) do
|
52
|
+
print ' Installing dependencies... '
|
53
|
+
bundle_install_output, status = Open3.capture2e('bundle', 'install', '--path', 'vendor/gems')
|
54
|
+
if status.success?
|
55
|
+
puts 'Done'
|
56
|
+
else
|
57
|
+
puts 'FAILED'
|
58
|
+
puts bundle_install_output
|
59
|
+
next
|
60
|
+
end
|
61
|
+
|
62
|
+
print ' Running baseline tests... '
|
63
|
+
baseline_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
|
64
|
+
if status.success?
|
65
|
+
puts 'Done'
|
66
|
+
else
|
67
|
+
puts 'Done (tests failed)'
|
68
|
+
end
|
69
|
+
|
70
|
+
print ' Updating Gemfile to use rspec-puppet HEAD... '
|
71
|
+
buffer = Parser::Source::Buffer.new('Gemfile')
|
72
|
+
buffer.source = File.read('Gemfile')
|
73
|
+
parser = Parser::CurrentRuby.new
|
74
|
+
ast = parser.parse(buffer)
|
75
|
+
|
76
|
+
modified_gemfile = GemfileRewrite.new.rewrite(buffer, ast)
|
77
|
+
|
78
|
+
gem_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
|
79
|
+
if modified_gemfile == buffer.source
|
80
|
+
File.open('Gemfile', 'a') do |f|
|
81
|
+
f.puts "gem 'rspec-puppet', :path => '#{gem_root}'"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
File.open('Gemfile', 'w') do |f|
|
85
|
+
f.puts modified_gemfile
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
puts 'Done'
|
90
|
+
|
91
|
+
print ' Installing dependencies... '
|
92
|
+
_, status = Open3.capture2e('bundle', 'install', '--path', 'vendor/gems')
|
93
|
+
if status.success?
|
94
|
+
puts 'Done'
|
95
|
+
else
|
96
|
+
puts "FAILED"
|
97
|
+
next
|
98
|
+
end
|
99
|
+
|
100
|
+
print ' Running tests against rspec-puppet HEAD... '
|
101
|
+
head_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
|
102
|
+
if status.success?
|
103
|
+
puts 'Done'
|
104
|
+
else
|
105
|
+
puts 'Done (tests failed)'
|
106
|
+
end
|
107
|
+
|
108
|
+
print ' Restoring Gemfile... '
|
109
|
+
_, status = Open3.capture2e('git', 'checkout', '--', 'Gemfile')
|
110
|
+
if status.success?
|
111
|
+
puts 'Done'
|
112
|
+
else
|
113
|
+
puts 'FAILED'
|
114
|
+
end
|
115
|
+
|
116
|
+
json_regex = %r{\{(?:[^{}]|(?:\g<0>))*\}}x
|
117
|
+
baseline_results = JSON.parse(baseline_output.scan(json_regex).last)
|
118
|
+
head_results = JSON.parse(head_output.scan(json_regex).last)
|
119
|
+
if head_results['summary_line'] == baseline_results['summary_line']
|
120
|
+
puts " PASS: #{head_results['summary_line']}"
|
121
|
+
else
|
122
|
+
puts "!!FAILED: baseline:(#{baseline_results['summary_line']}) head:(#{head_results['summary_line']})"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class GemfileRewrite < Parser::Rewriter
|
131
|
+
def on_send(node)
|
132
|
+
_, method_name, *args = *node
|
133
|
+
|
134
|
+
if method_name == :gem
|
135
|
+
gem_name = args.first
|
136
|
+
if gem_name.type == :str && gem_name.children.first == 'rspec-puppet'
|
137
|
+
gem_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
|
138
|
+
replace(node.location.expression, "gem 'rspec-puppet', :path => '#{gem_root}'")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
super
|
143
|
+
end
|
144
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/rspec-puppet.rb
|
38
38
|
- lib/rspec-puppet/adapters.rb
|
39
39
|
- lib/rspec-puppet/cache.rb
|
40
|
+
- lib/rspec-puppet/consts.rb
|
40
41
|
- lib/rspec-puppet/coverage.rb
|
41
42
|
- lib/rspec-puppet/errors.rb
|
42
43
|
- lib/rspec-puppet/example.rb
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- lib/rspec-puppet/setup.rb
|
65
66
|
- lib/rspec-puppet/spec_helper.rb
|
66
67
|
- lib/rspec-puppet/support.rb
|
68
|
+
- lib/rspec-puppet/tasks/release_test.rb
|
67
69
|
homepage: https://github.com/rodjek/rspec-puppet/
|
68
70
|
licenses:
|
69
71
|
- MIT
|