rspec-puppet 2.6.9 → 2.6.10
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 +47 -0
- data/README.md +9 -0
- data/lib/rspec-puppet.rb +15 -0
- data/lib/rspec-puppet/adapters.rb +1 -0
- data/lib/rspec-puppet/coverage.rb +2 -0
- data/lib/rspec-puppet/matchers/parameter_matcher.rb +10 -0
- data/lib/rspec-puppet/monkey_patches.rb +38 -1
- data/lib/rspec-puppet/monkey_patches/win32/registry.rb +79 -0
- data/lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb +159 -0
- data/lib/rspec-puppet/setup.rb +4 -4
- data/lib/rspec-puppet/support.rb +68 -23
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79d6d3a697c31a222aeeed78ed607388ea642626
|
4
|
+
data.tar.gz: 22bcbe25913fcc858d11f4d5842525fd5f891dd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4eb8e8725a5373c0b4fb965b0ac0804ec6003696f5e202cabf88240412b5fe35613a5613544ce22b3c31ce6a055b8463206d7b6c0cb13be427d1c4d812e68fb
|
7
|
+
data.tar.gz: da2762a48d9cf1096c84eb01faf1595709a3bffb8cbb3b95128feb7f2c8e9a1527d8bfa8892cc1798f7342cb1f0c86145b3c5df2b522c9cdb3d3bced10f17104
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,53 @@
|
|
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.10]
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* Replaced deprecated `File.exists?` calls in `rspec-puppet-init` with
|
10
|
+
`File.exist?`, which behaves much more reliably in respect to symlinks.
|
11
|
+
* Stubbed out `Puppet::Util::Windows::Security.supports_acl?` when compiling
|
12
|
+
the catalogue as this check only make sense when applying the resources to
|
13
|
+
a host and prevents testing Windows File resources on non-Windows hosts.
|
14
|
+
* The cached default provider for native types is now reset before compiling
|
15
|
+
a new catalogue.
|
16
|
+
* Resource titles that contain single quotes are now rendered correctly,
|
17
|
+
allowing them to be tested.
|
18
|
+
* When pretending to be a different platform, the methods in
|
19
|
+
`Puppet::Util::Platform` are now stubbed after the catalogue has been
|
20
|
+
compiled, allowing path related logic in custom facts to behave as expected.
|
21
|
+
* A mock version of `Win32::TaskScheduler` has been added to rspec-puppet.
|
22
|
+
This will be loaded when running rspec-puppet on a non-Windows host in order
|
23
|
+
to allow testing of catalogues containing Scheduled\_task resources.
|
24
|
+
* Stubbed out the `manages_symlinks` feature on
|
25
|
+
`Puppet::Type::File::ProviderWindows` as this can only be evaluated at apply
|
26
|
+
time and prevents testing Windows File resources that manage symlinks on
|
27
|
+
non-Windows hosts.
|
28
|
+
* Fixed unhandled exception when testing resource parameters where the
|
29
|
+
expected value is an Array or a Hash and the actual value is a different
|
30
|
+
data type.
|
31
|
+
* A mock version of `Win32::Registry` has been added to rspec-puppet. This
|
32
|
+
will be loaded when running rspec-puppet on a non-Windows host in order to
|
33
|
+
allow testing of catalogues that contain Exec resources that use the
|
34
|
+
`powershell` provider from the `puppetlabs/puppetlabs-powershell` module.
|
35
|
+
* Fixed a case where the order in which tests are run can cause a resource
|
36
|
+
that is being tested to be falsely reported as untested in the coverage
|
37
|
+
report.
|
38
|
+
|
39
|
+
### Changed
|
40
|
+
|
41
|
+
* The tests for the `compile` matcher have been updated to support the new
|
42
|
+
error message format introduced in Puppet 5.3.4.
|
43
|
+
* The builtin `$server_facts` hash is now populated on versions of Puppet that
|
44
|
+
support it (Puppet >= 4.3). This is not currently enabled by default, but
|
45
|
+
can be enabled by setting `RSpec.configuration.trusted_server_facts` to
|
46
|
+
`true`.
|
47
|
+
* `$facts['os']['family']` and `$facts['os']['name']` are now checked when
|
48
|
+
determining if rspec-puppet needs to pretend to be running on a different
|
49
|
+
platform (previously only `$facts['operatingsystem']` and
|
50
|
+
`$facts['osfamily']` were used).
|
51
|
+
|
5
52
|
## [2.6.9]
|
6
53
|
|
7
54
|
### Fixed
|
data/README.md
CHANGED
@@ -105,6 +105,14 @@ Boolean | `false` | >=3.4, 4.x, 5.x
|
|
105
105
|
Configures rspec-puppet to use the `$trusted` hash when compiling the
|
106
106
|
catalogues.
|
107
107
|
|
108
|
+
#### trusted\_server\_facts
|
109
|
+
Type | Default | Puppet Version(s)
|
110
|
+
------- | ------- | -----------------
|
111
|
+
Boolean | `false` | >=4.3, 5.x
|
112
|
+
|
113
|
+
Configures rspec-puppet to use the `$server_facts` hash when compiling the
|
114
|
+
catalogues.
|
115
|
+
|
108
116
|
#### confdir
|
109
117
|
Type | Default | Puppet Version(s)
|
110
118
|
------ | --------------- | ------------------
|
@@ -1047,6 +1055,7 @@ be excluded from the coverage report.
|
|
1047
1055
|
* [puppetlabs_spec_helper](https://github.com/puppetlabs/puppetlabs_spec_helper): shared spec helpers to setup puppet
|
1048
1056
|
* [rspec-puppet-augeas](https://github.com/domcleal/rspec-puppet-augeas): RSpec tests for Augeas resources inside Puppet manifests
|
1049
1057
|
* [jimdo-rspec-puppet-helpers](https://github.com/Jimdo/jimdo-rspec-puppet-helpers): Tests the contents of a file with a source
|
1058
|
+
* [puppet-catalog_rspec](https://github.com/enterprisemodules/puppet-catalog_rspec): Ease development of specs by dumping the Puppet catalog as RSpec code
|
1050
1059
|
|
1051
1060
|
* Fact providers
|
1052
1061
|
* [rspec-puppet-facts](https://github.com/mcanevet/rspec-puppet-facts): Simplify your unit tests by looping on every supported Operating System and populating facts.
|
data/lib/rspec-puppet.rb
CHANGED
@@ -23,6 +23,10 @@ module RSpec::Puppet
|
|
23
23
|
def self.rspec_puppet_example?
|
24
24
|
RSpec::Puppet::EventListener.rspec_puppet_example?
|
25
25
|
end
|
26
|
+
|
27
|
+
def self.current_example
|
28
|
+
RSpec::Puppet::EventListener.current_example
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
require 'rspec-puppet/monkey_patches'
|
@@ -49,6 +53,17 @@ RSpec.configure do |c|
|
|
49
53
|
c.add_setting :adapter
|
50
54
|
c.add_setting :platform, :default => Puppet::Util::Platform.actual_platform
|
51
55
|
|
56
|
+
c.instance_eval do
|
57
|
+
def trusted_server_facts
|
58
|
+
@trusted_server_facts.nil? ? false : @trusted_server_facts
|
59
|
+
end
|
60
|
+
|
61
|
+
def trusted_server_facts=(value)
|
62
|
+
@trusted_server_facts = value
|
63
|
+
adapter.setup_puppet(RSpec::Puppet.current_example) unless adapter.nil?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
52
67
|
c.before(:all) do
|
53
68
|
if RSpec.configuration.setup_fixtures?
|
54
69
|
RSpec::Puppet::Setup.safe_setup_directories(nil, false)
|
@@ -119,6 +119,8 @@ module RSpec::Puppet
|
|
119
119
|
def results
|
120
120
|
report = {}
|
121
121
|
|
122
|
+
@collection.delete_if { |name, _| filtered?(name) }
|
123
|
+
|
122
124
|
report[:total] = @collection.size
|
123
125
|
report[:touched] = @collection.count { |_, resource| resource.touched? }
|
124
126
|
report[:untouched] = report[:total] - report[:touched]
|
@@ -87,6 +87,11 @@ module RSpec::Puppet
|
|
87
87
|
def check_hash(expected, actual)
|
88
88
|
op = @should_match ? :"==" : :"!="
|
89
89
|
|
90
|
+
unless actual.class.send(op, expected.class)
|
91
|
+
@errors << MatchError.new(@parameter, expected, actual, !@should_match)
|
92
|
+
return false
|
93
|
+
end
|
94
|
+
|
90
95
|
unless expected.keys.size.send(op, actual.keys.size)
|
91
96
|
return false
|
92
97
|
end
|
@@ -99,6 +104,11 @@ module RSpec::Puppet
|
|
99
104
|
def check_array(expected, actual)
|
100
105
|
op = @should_match ? :"==" : :"!="
|
101
106
|
|
107
|
+
unless actual.class.send(op, expected.class)
|
108
|
+
@errors << MatchError.new(@parameter, expected, actual, !@should_match)
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
|
102
112
|
unless expected.size.send(op, actual.size)
|
103
113
|
return false
|
104
114
|
end
|
@@ -11,8 +11,13 @@ class RSpec::Puppet::EventListener
|
|
11
11
|
def self.example_started(example)
|
12
12
|
if rspec3?
|
13
13
|
@rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support)
|
14
|
+
@current_example = example.example
|
15
|
+
if !@current_example.respond_to?(:environment) && @current_example.respond_to?(:example_group_instance)
|
16
|
+
@current_example = @current_example.example_group_instance
|
17
|
+
end
|
14
18
|
else
|
15
19
|
@rspec_puppet_example = example.example_group.ancestors.include?(RSpec::Puppet::Support)
|
20
|
+
@current_example = example
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
@@ -39,10 +44,17 @@ class RSpec::Puppet::EventListener
|
|
39
44
|
|
40
45
|
@rspec3
|
41
46
|
end
|
47
|
+
|
48
|
+
def self.current_example
|
49
|
+
@current_example
|
50
|
+
end
|
42
51
|
end
|
43
52
|
|
44
53
|
RSpec.configuration.reporter.register_listener(RSpec::Puppet::EventListener, :example_started, :example_pending, :example_passed, :example_failed)
|
45
54
|
|
55
|
+
require 'rspec-puppet/monkey_patches/win32/taskscheduler'
|
56
|
+
require 'rspec-puppet/monkey_patches/win32/registry'
|
57
|
+
|
46
58
|
module Puppet
|
47
59
|
# Allow rspec-puppet to prevent Puppet::Type from automatically picking
|
48
60
|
# a provider for a resource. We need to do this because in order to fully
|
@@ -272,13 +284,38 @@ Puppet::Type.type(:exec).paramclass(:user).validate do |value|
|
|
272
284
|
end
|
273
285
|
end
|
274
286
|
|
287
|
+
# Stub out Puppet::Util::Windows::Security.supports_acl? if it has been
|
288
|
+
# defined. This check only makes sense when applying the catalogue to a host
|
289
|
+
# and so can be safely stubbed out for unit testing.
|
290
|
+
Puppet::Type.type(:file).provide(:windows).class_eval do
|
291
|
+
old_supports_acl = instance_method(:supports_acl?) if respond_to?(:supports_acl?)
|
292
|
+
|
293
|
+
def supports_acl?(path)
|
294
|
+
if RSpec::Puppet.rspec_puppet_example?
|
295
|
+
true
|
296
|
+
else
|
297
|
+
old_supports_acl.bind(self).call(value)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
old_manages_symlinks = instance_method(:manages_symlinks?) if respond_to?(:manages_symlinks?)
|
302
|
+
|
303
|
+
def manages_symlinks?
|
304
|
+
if RSpec::Puppet.rspec_puppet_example?
|
305
|
+
true
|
306
|
+
else
|
307
|
+
old_manages_symlinks.bind(self).call(value)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
275
312
|
# Prevent Puppet from requiring 'puppet/util/windows' if we're pretending to be
|
276
313
|
# windows, otherwise it will require other libraries that probably won't be
|
277
314
|
# available on non-windows hosts.
|
278
315
|
module Kernel
|
279
316
|
alias :old_require :require
|
280
317
|
def require(path)
|
281
|
-
return if
|
318
|
+
return if (['puppet/util/windows', 'win32/registry'].include?(path)) && RSpec::Puppet.rspec_puppet_example? && Puppet::Util::Platform.pretend_windows?
|
282
319
|
old_require(path)
|
283
320
|
end
|
284
321
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Puppet
|
3
|
+
module Win32
|
4
|
+
class Registry
|
5
|
+
module Constants
|
6
|
+
HKEY_CLASSES_ROOT = 0x80000000
|
7
|
+
HKEY_CURRENT_USER = 0x80000001
|
8
|
+
HKEY_LOCAL_MACHINE = 0x80000002
|
9
|
+
HKEY_USERS = 0x80000003
|
10
|
+
HKEY_PERFORMANCE_DATA = 0x80000004
|
11
|
+
HKEY_PERFORMANCE_TEXT = 0x80000050
|
12
|
+
HKEY_PERFORMANCE_NLSTEXT = 0x80000060
|
13
|
+
HKEY_CURRENT_CONFIG = 0x80000005
|
14
|
+
HKEY_DYN_DATA = 0x80000006
|
15
|
+
|
16
|
+
REG_NONE = 0
|
17
|
+
REG_SZ = 1
|
18
|
+
REG_EXPAND_SZ = 2
|
19
|
+
REG_BINARY = 3
|
20
|
+
REG_DWORD = 4
|
21
|
+
REG_DWORD_LITTLE_ENDIAN = 4
|
22
|
+
REG_DWORD_BIG_ENDIAN = 5
|
23
|
+
REG_LINK = 6
|
24
|
+
REG_MULTI_SZ = 7
|
25
|
+
REG_RESOURCE_LIST = 8
|
26
|
+
REG_FULL_RESOURCE_DESCRIPTOR = 9
|
27
|
+
REG_RESOURCE_REQUIREMENTS_LIST = 10
|
28
|
+
REG_QWORD = 11
|
29
|
+
REG_QWORD_LITTLE_ENDIAN = 11
|
30
|
+
|
31
|
+
STANDARD_RIGHTS_READ = 0x00020000
|
32
|
+
STANDARD_RIGHTS_WRITE = 0x00020000
|
33
|
+
KEY_QUERY_VALUE = 0x0001
|
34
|
+
KEY_SET_VALUE = 0x0002
|
35
|
+
KEY_CREATE_SUB_KEY = 0x0004
|
36
|
+
KEY_ENUMERATE_SUB_KEYS = 0x0008
|
37
|
+
KEY_NOTIFY = 0x0010
|
38
|
+
KEY_CREATE_LINK = 0x0020
|
39
|
+
KEY_READ = STANDARD_RIGHTS_READ |
|
40
|
+
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
|
41
|
+
KEY_WRITE = STANDARD_RIGHTS_WRITE |
|
42
|
+
KEY_SET_VALUE | KEY_CREATE_SUB_KEY
|
43
|
+
KEY_EXECUTE = KEY_READ
|
44
|
+
KEY_ALL_ACCESS = KEY_READ | KEY_WRITE | KEY_CREATE_LINK
|
45
|
+
|
46
|
+
REG_OPTION_RESERVED = 0x0000
|
47
|
+
REG_OPTION_NON_VOLATILE = 0x0000
|
48
|
+
REG_OPTION_VOLATILE = 0x0001
|
49
|
+
REG_OPTION_CREATE_LINK = 0x0002
|
50
|
+
REG_OPTION_BACKUP_RESTORE = 0x0004
|
51
|
+
REG_OPTION_OPEN_LINK = 0x0008
|
52
|
+
REG_LEGAL_OPTION = REG_OPTION_RESERVED |
|
53
|
+
REG_OPTION_NON_VOLATILE | REG_OPTION_CREATE_LINK |
|
54
|
+
REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK
|
55
|
+
|
56
|
+
REG_CREATED_NEW_KEY = 1
|
57
|
+
REG_OPENED_EXISTING_KEY = 2
|
58
|
+
|
59
|
+
REG_WHOLE_HIVE_VOLATILE = 0x0001
|
60
|
+
REG_REFRESH_HIVE = 0x0002
|
61
|
+
REG_NO_LAZY_FLUSH = 0x0004
|
62
|
+
REG_FORCE_RESTORE = 0x0008
|
63
|
+
|
64
|
+
MAX_KEY_LENGTH = 514
|
65
|
+
MAX_VALUE_LENGTH = 32768
|
66
|
+
end
|
67
|
+
include Constants
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
begin
|
74
|
+
require 'win32/registry'
|
75
|
+
rescue LoadError
|
76
|
+
module Win32
|
77
|
+
Registry = RSpec::Puppet::Win32::Registry
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# Create our dummy Win32::TaskScheduler with the consts defined from
|
2
|
+
# https://github.com/djberg96/win32-taskscheduler/blob/ole/lib/win32/taskscheduler.rb
|
3
|
+
module RSpec
|
4
|
+
module Puppet
|
5
|
+
module Win32
|
6
|
+
class TaskScheduler
|
7
|
+
TASK_TIME_TRIGGER_ONCE = 0
|
8
|
+
TASK_TIME_TRIGGER_DAILY = 1
|
9
|
+
TASK_TIME_TRIGGER_WEEKLY = 2
|
10
|
+
TASK_TIME_TRIGGER_MONTHLYDATE = 3
|
11
|
+
TASK_TIME_TRIGGER_MONTHLYDOW = 4
|
12
|
+
TASK_EVENT_TRIGGER_ON_IDLE = 5
|
13
|
+
TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6
|
14
|
+
TASK_EVENT_TRIGGER_AT_LOGON = 7
|
15
|
+
ONCE = TASK_TIME_TRIGGER_ONCE
|
16
|
+
DAILY = TASK_TIME_TRIGGER_DAILY
|
17
|
+
WEEKLY = TASK_TIME_TRIGGER_WEEKLY
|
18
|
+
MONTHLYDATE = TASK_TIME_TRIGGER_MONTHLYDATE
|
19
|
+
MONTHLYDOW = TASK_TIME_TRIGGER_MONTHLYDOW
|
20
|
+
ON_IDLE = TASK_EVENT_TRIGGER_ON_IDLE
|
21
|
+
AT_SYSTEMSTART = TASK_EVENT_TRIGGER_AT_SYSTEMSTART
|
22
|
+
AT_LOGON = TASK_EVENT_TRIGGER_AT_LOGON
|
23
|
+
|
24
|
+
TASK_SUNDAY = 0x1
|
25
|
+
TASK_MONDAY = 0x2
|
26
|
+
TASK_TUESDAY = 0x4
|
27
|
+
TASK_WEDNESDAY = 0x8
|
28
|
+
TASK_THURSDAY = 0x10
|
29
|
+
TASK_FRIDAY = 0x20
|
30
|
+
TASK_SATURDAY = 0x40
|
31
|
+
SUNDAY = TASK_SUNDAY
|
32
|
+
MONDAY = TASK_MONDAY
|
33
|
+
TUESDAY = TASK_TUESDAY
|
34
|
+
WEDNESDAY = TASK_WEDNESDAY
|
35
|
+
THURSDAY = TASK_THURSDAY
|
36
|
+
FRIDAY = TASK_FRIDAY
|
37
|
+
SATURDAY = TASK_SATURDAY
|
38
|
+
|
39
|
+
TASK_FIRST_WEEK = 1
|
40
|
+
TASK_SECOND_WEEK = 2
|
41
|
+
TASK_THIRD_WEEK = 3
|
42
|
+
TASK_FOURTH_WEEK = 4
|
43
|
+
TASK_LAST_WEEK = 5
|
44
|
+
FIRST_WEEK = TASK_FIRST_WEEK
|
45
|
+
SECOND_WEEK = TASK_SECOND_WEEK
|
46
|
+
THIRD_WEEK = TASK_THIRD_WEEK
|
47
|
+
FOURTH_WEEK = TASK_FOURTH_WEEK
|
48
|
+
LAST_WEEK = TASK_LAST_WEEK
|
49
|
+
|
50
|
+
TASK_JANUARY = 0x1
|
51
|
+
TASK_FEBRUARY = 0x2
|
52
|
+
TASK_MARCH = 0x4
|
53
|
+
TASK_APRIL = 0x8
|
54
|
+
TASK_MAY = 0x10
|
55
|
+
TASK_JUNE = 0x20
|
56
|
+
TASK_JULY = 0x40
|
57
|
+
TASK_AUGUST = 0x80
|
58
|
+
TASK_SEPTEMBER = 0x100
|
59
|
+
TASK_OCTOBER = 0x200
|
60
|
+
TASK_NOVEMBER = 0x400
|
61
|
+
TASK_DECEMBER = 0x800
|
62
|
+
JANUARY = TASK_JANUARY
|
63
|
+
FEBRUARY = TASK_FEBRUARY
|
64
|
+
MARCH = TASK_MARCH
|
65
|
+
APRIL = TASK_APRIL
|
66
|
+
MAY = TASK_MAY
|
67
|
+
JUNE = TASK_JUNE
|
68
|
+
JULY = TASK_JULY
|
69
|
+
AUGUST = TASK_AUGUST
|
70
|
+
SEPTEMBER = TASK_SEPTEMBER
|
71
|
+
OCTOBER = TASK_OCTOBER
|
72
|
+
NOVEMBER = TASK_NOVEMBER
|
73
|
+
DECEMBER = TASK_DECEMBER
|
74
|
+
|
75
|
+
TASK_FLAG_INTERACTIVE = 0x1
|
76
|
+
TASK_FLAG_DELETE_WHEN_DONE = 0x2
|
77
|
+
TASK_FLAG_DISABLED = 0x4
|
78
|
+
TASK_FLAG_START_ONLY_IF_IDLE = 0x10
|
79
|
+
TASK_FLAG_KILL_ON_IDLE_END = 0x20
|
80
|
+
TASK_FLAG_DONT_START_IF_ON_BATTERIES = 0x40
|
81
|
+
TASK_FLAG_KILL_IF_GOING_ON_BATTERIES = 0x80
|
82
|
+
TASK_FLAG_RUN_ONLY_IF_DOCKED = 0x100
|
83
|
+
TASK_FLAG_HIDDEN = 0x200
|
84
|
+
TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET = 0x400
|
85
|
+
TASK_FLAG_RESTART_ON_IDLE_RESUME = 0x800
|
86
|
+
TASK_FLAG_SYSTEM_REQUIRED = 0x1000
|
87
|
+
TASK_FLAG_RUN_ONLY_IF_LOGGED_ON = 0x2000
|
88
|
+
INTERACTIVE = TASK_FLAG_INTERACTIVE
|
89
|
+
DELETE_WHEN_DONE = TASK_FLAG_DELETE_WHEN_DONE
|
90
|
+
DISABLED = TASK_FLAG_DISABLED
|
91
|
+
START_ONLY_IF_IDLE = TASK_FLAG_START_ONLY_IF_IDLE
|
92
|
+
KILL_ON_IDLE_END = TASK_FLAG_KILL_ON_IDLE_END
|
93
|
+
DONT_START_IF_ON_BATTERIES = TASK_FLAG_DONT_START_IF_ON_BATTERIES
|
94
|
+
KILL_IF_GOING_ON_BATTERIES = TASK_FLAG_KILL_IF_GOING_ON_BATTERIES
|
95
|
+
RUN_ONLY_IF_DOCKED = TASK_FLAG_RUN_ONLY_IF_DOCKED
|
96
|
+
HIDDEN = TASK_FLAG_HIDDEN
|
97
|
+
RUN_IF_CONNECTED_TO_INTERNET = TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET
|
98
|
+
RESTART_ON_IDLE_RESUME = TASK_FLAG_RESTART_ON_IDLE_RESUME
|
99
|
+
SYSTEM_REQUIRED = TASK_FLAG_SYSTEM_REQUIRED
|
100
|
+
RUN_ONLY_IF_LOGGED_ON = TASK_FLAG_RUN_ONLY_IF_LOGGED_ON
|
101
|
+
|
102
|
+
TASK_TRIGGER_FLAG_HAS_END_DATE = 0x1
|
103
|
+
TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = 0x2
|
104
|
+
TASK_TRIGGER_FLAG_DISABLED = 0x4
|
105
|
+
FLAG_HAS_END_DATE = TASK_TRIGGER_FLAG_HAS_END_DATE
|
106
|
+
FLAG_KILL_AT_DURATION_END = TASK_TRIGGER_FLAG_KILL_AT_DURATION_END
|
107
|
+
FLAG_DISABLED = TASK_TRIGGER_FLAG_DISABLED
|
108
|
+
|
109
|
+
TASK_MAX_RUN_TIMES = 1440
|
110
|
+
TASKS_TO_RETRIEVE = 5
|
111
|
+
MAX_RUN_TIMES = TASK_MAX_RUN_TIMES
|
112
|
+
|
113
|
+
TASK_VALIDATE_ONLY = 0x1
|
114
|
+
TASK_CREATE = 0x2
|
115
|
+
TASK_UPDATE = 0x4
|
116
|
+
TASK_CREATE_OR_UPDATE = 0x6
|
117
|
+
TASK_DISABLE = 0x8
|
118
|
+
TASK_DONT_ADD_PRINCIPAL_ACE = 0x10
|
119
|
+
TASK_IGNORE_REGISTRATION_TRIGGERS = 0x20
|
120
|
+
|
121
|
+
TASK_LOGON_NONE = 0
|
122
|
+
TASK_LOGON_PASSWORD = 1
|
123
|
+
TASK_LOGON_S4U = 2
|
124
|
+
TASK_LOGON_INTERACTIVE_TOKEN = 3
|
125
|
+
TASK_LOGON_GROUP = 4
|
126
|
+
TASK_LOGON_SERVICE_ACCOUNT = 5
|
127
|
+
TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD = 6
|
128
|
+
|
129
|
+
REALTIME_PRIORITY_CLASS = 0
|
130
|
+
HIGH_PRIORITY_CLASS = 1
|
131
|
+
ABOVE_NORMAL_PRIORITY_CLASS = 2
|
132
|
+
NORMAL_PRIORITY_CLASS = 4
|
133
|
+
BELOW_NORMAL_PRIORITY_CLASS = 7
|
134
|
+
IDLE_PRIORITY_CLASS = 9
|
135
|
+
REALTIME = REALTIME_PRIORITY_CLASS
|
136
|
+
HIGH = HIGH_PRIORITY_CLASS
|
137
|
+
ABOVE_NORMAL = ABOVE_NORMAL_PRIORITY_CLASS
|
138
|
+
NORMAL = NORMAL_PRIORITY_CLASS
|
139
|
+
BELOW_NORMAL = BELOW_NORMAL_PRIORITY_CLASS
|
140
|
+
IDLE = IDLE_PRIORITY_CLASS
|
141
|
+
|
142
|
+
CLSCTX_INPROC_SERVER = 0x1
|
143
|
+
CLSID_CTask = [0x148BD520,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
|
144
|
+
CLSID_CTaskScheduler = [0x148BD52A,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
|
145
|
+
IID_ITaskScheduler = [0x148BD527,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
|
146
|
+
IID_ITask = [0x148BD524,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
|
147
|
+
IID_IPersistFile = [0x0000010b,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46].pack('LSSC8')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
begin
|
154
|
+
require 'win32/taskscheduler'
|
155
|
+
rescue LoadError
|
156
|
+
module Win32
|
157
|
+
TaskScheduler = RSpec::Puppet::Win32::TaskScheduler
|
158
|
+
end
|
159
|
+
end
|
data/lib/rspec-puppet/setup.rb
CHANGED
@@ -109,7 +109,7 @@ END
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def self.safe_mkdir(dir, verbose=true)
|
112
|
-
if File.
|
112
|
+
if File.exist? dir
|
113
113
|
unless File.directory? dir
|
114
114
|
$stderr.puts "!! #{dir} already exists and is not a directory"
|
115
115
|
end
|
@@ -124,7 +124,7 @@ END
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def self.safe_touch(file)
|
127
|
-
if File.
|
127
|
+
if File.exist? file
|
128
128
|
unless File.file? file
|
129
129
|
$stderr.puts "!! #{file} already exists and is not a regular file"
|
130
130
|
end
|
@@ -135,7 +135,7 @@ END
|
|
135
135
|
end
|
136
136
|
|
137
137
|
def self.safe_create_file(filename, content)
|
138
|
-
if File.
|
138
|
+
if File.exist? filename
|
139
139
|
old_content = File.read(filename)
|
140
140
|
if old_content != content
|
141
141
|
$stderr.puts "!! #{filename} already exists and differs from template"
|
@@ -154,7 +154,7 @@ END
|
|
154
154
|
end
|
155
155
|
|
156
156
|
def self.safe_make_link(source, target, verbose=true)
|
157
|
-
if File.
|
157
|
+
if File.exist?(target)
|
158
158
|
unless File.symlink?(target) && File.readlink(target) == File.expand_path(source)
|
159
159
|
$stderr.puts "!! #{target} already exists and is not a symlink"
|
160
160
|
end
|
data/lib/rspec-puppet/support.rb
CHANGED
@@ -54,17 +54,29 @@ module RSpec::Puppet
|
|
54
54
|
|
55
55
|
munged_facts = facts_hash(nodename(type))
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
pretend_platform = find_pretend_platform(munged_facts)
|
58
|
+
RSpec::Puppet::Consts.stub_consts_for(pretend_platform) unless pretend_platform.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_pretend_platform(test_facts)
|
62
|
+
from_value = lambda { |value|
|
63
|
+
value.to_s.downcase == 'windows' ? :windows : :posix
|
64
|
+
}
|
65
|
+
|
66
|
+
['operatingsystem', 'osfamily', 'os'].each do |os_fact|
|
67
|
+
return from_value.call(test_facts[os_fact]) if test_facts.key?(os_fact)
|
68
|
+
end
|
69
|
+
|
70
|
+
if test_facts.key?('os') && test_facts['os'].is_a?(Hash)
|
71
|
+
['name', 'family'].each do |os_hash_key|
|
72
|
+
return from_value.call(test_facts['os'][os_hash_key]) if test_facts['os'].key?(os_hash_key)
|
64
73
|
end
|
65
74
|
end
|
75
|
+
|
76
|
+
nil
|
66
77
|
end
|
67
78
|
|
79
|
+
|
68
80
|
def load_catalogue(type, exported = false, manifest_opts = {})
|
69
81
|
with_vardir do
|
70
82
|
node_name = nodename(type)
|
@@ -72,8 +84,10 @@ module RSpec::Puppet
|
|
72
84
|
hiera_config_value = self.respond_to?(:hiera_config) ? hiera_config : nil
|
73
85
|
hiera_data_value = self.respond_to?(:hiera_data) ? hiera_data : nil
|
74
86
|
|
75
|
-
|
76
|
-
|
87
|
+
build_facts = facts_hash(node_name)
|
88
|
+
catalogue = build_catalog(node_name, build_facts, trusted_facts_hash(node_name), hiera_config_value,
|
89
|
+
build_code(type, manifest_opts), exported, node_params_hash, hiera_data_value,
|
90
|
+
RSpec.configuration.trusted_server_facts)
|
77
91
|
|
78
92
|
test_module = type == :host ? nil : class_name.split('::').first
|
79
93
|
if type == :define
|
@@ -83,6 +97,9 @@ module RSpec::Puppet
|
|
83
97
|
end
|
84
98
|
RSpec::Puppet::Coverage.add_from_catalog(catalogue, test_module)
|
85
99
|
|
100
|
+
pretend_platform = find_pretend_platform(build_facts)
|
101
|
+
Puppet::Util::Platform.pretend_to_be(pretend_platform) unless pretend_platform.nil?
|
102
|
+
|
86
103
|
catalogue
|
87
104
|
end
|
88
105
|
end
|
@@ -132,15 +149,15 @@ module RSpec::Puppet
|
|
132
149
|
end
|
133
150
|
elsif type == :application
|
134
151
|
if opts.has_key?(:params)
|
135
|
-
"site { #{class_name} {
|
152
|
+
"site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"
|
136
153
|
else
|
137
154
|
raise ArgumentError, "You need to provide params for an application"
|
138
155
|
end
|
139
156
|
elsif type == :define
|
140
157
|
title_str = if title.is_a?(Array)
|
141
|
-
'[' + title.map { |r|
|
158
|
+
'[' + title.map { |r| sanitise_resource_title(r) }.join(', ') + ']'
|
142
159
|
else
|
143
|
-
|
160
|
+
sanitise_resource_title(title)
|
144
161
|
end
|
145
162
|
if opts.has_key?(:params)
|
146
163
|
"#{class_name} { #{title_str}: #{param_str(opts[:params])} }"
|
@@ -154,6 +171,10 @@ module RSpec::Puppet
|
|
154
171
|
end
|
155
172
|
end
|
156
173
|
|
174
|
+
def sanitise_resource_title(title)
|
175
|
+
title.include?("'") ? title.inspect : "'#{title}'"
|
176
|
+
end
|
177
|
+
|
157
178
|
def nodename(type)
|
158
179
|
return node if self.respond_to?(:node)
|
159
180
|
if [:class, :define, :function, :application].include? type
|
@@ -264,6 +285,34 @@ module RSpec::Puppet
|
|
264
285
|
extensions
|
265
286
|
end
|
266
287
|
|
288
|
+
def server_facts_hash
|
289
|
+
server_facts = {}
|
290
|
+
|
291
|
+
# Add our server version to the fact list
|
292
|
+
server_facts["serverversion"] = Puppet.version.to_s
|
293
|
+
|
294
|
+
# And then add the server name and IP
|
295
|
+
{"servername" => "fqdn",
|
296
|
+
"serverip" => "ipaddress"
|
297
|
+
}.each do |var, fact|
|
298
|
+
if value = Facter.value(fact)
|
299
|
+
server_facts[var] = value
|
300
|
+
else
|
301
|
+
warn "Could not retrieve fact #{fact}"
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
if server_facts["servername"].nil?
|
306
|
+
host = Facter.value(:hostname)
|
307
|
+
if domain = Facter.value(:domain)
|
308
|
+
server_facts["servername"] = [host, domain].join(".")
|
309
|
+
else
|
310
|
+
server_facts["servername"] = host
|
311
|
+
end
|
312
|
+
end
|
313
|
+
server_facts
|
314
|
+
end
|
315
|
+
|
267
316
|
def str_from_value(value)
|
268
317
|
case value
|
269
318
|
when Hash
|
@@ -337,6 +386,8 @@ module RSpec::Puppet
|
|
337
386
|
|
338
387
|
stub_facts! facts_val
|
339
388
|
|
389
|
+
Puppet::Type.eachtype { |type| type.defaultprovider = nil }
|
390
|
+
|
340
391
|
node_facts = Puppet::Node::Facts.new(nodename, facts_val.dup)
|
341
392
|
node_params = facts_val.merge(node_params)
|
342
393
|
|
@@ -351,26 +402,20 @@ module RSpec::Puppet
|
|
351
402
|
)
|
352
403
|
end
|
353
404
|
|
405
|
+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
|
406
|
+
node_obj.add_server_facts(server_facts_hash)
|
407
|
+
end
|
408
|
+
|
354
409
|
adapter.catalog(node_obj, exported)
|
355
410
|
end
|
356
411
|
|
357
412
|
def stub_facts!(facts)
|
358
413
|
Puppet.settings[:autosign] = false
|
414
|
+
Facter.clear
|
359
415
|
facts.each { |k, v| Facter.add(k) { setcode { v } } }
|
360
416
|
end
|
361
417
|
|
362
418
|
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
|
-
|
374
419
|
@@cache.get(*args) do |*args|
|
375
420
|
build_catalog_without_cache(*args)
|
376
421
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -60,6 +60,8 @@ files:
|
|
60
60
|
- lib/rspec-puppet/matchers/run.rb
|
61
61
|
- lib/rspec-puppet/matchers/type_matchers.rb
|
62
62
|
- lib/rspec-puppet/monkey_patches.rb
|
63
|
+
- lib/rspec-puppet/monkey_patches/win32/registry.rb
|
64
|
+
- lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb
|
63
65
|
- lib/rspec-puppet/rake_task.rb
|
64
66
|
- lib/rspec-puppet/raw_string.rb
|
65
67
|
- lib/rspec-puppet/setup.rb
|
@@ -86,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
88
|
version: '0'
|
87
89
|
requirements: []
|
88
90
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.6.
|
91
|
+
rubygems_version: 2.6.13
|
90
92
|
signing_key:
|
91
93
|
specification_version: 4
|
92
94
|
summary: RSpec tests for your Puppet manifests
|