puppet-unit-tests 0.1.0 → 0.3.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/README.md +17 -4
- data/assets/test-env/hiera.yaml +12 -0
- data/assets/test-env/lib/puppet/functions/test_data.rb +26 -0
- data/lib/puppet_unit_tests/rake_task.rb +1 -1
- data/lib/puppet_unit_tests/runner.rb +30 -10
- data/lib/puppet_unit_tests/test_data.rb +1 -1
- data/lib/puppet_unit_tests/test_environment.rb +3 -1
- data/lib/puppet_unit_tests/version.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 65355d1254f33d3c4a19d2407ca278b7c3e29e7b1240f9a2e5489e62eb90eeb7
|
|
4
|
+
data.tar.gz: 9823aac83e42222e742682ab4f95316f62e2ba4d9651ef3c7bbbeba1564e828a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe22c553caef295c6ce078abd9bd19329671db34cfa525041868dabe3a0dfb6f785f45792f548d6fba24aa67e40add6095a68905b065d7b4e23e15d38a532197
|
|
7
|
+
data.tar.gz: 807ed15b9a99e640ad4fe77f8c619806c11d7a27eed56defef1078a3c52517d7dcd88498df9d6d392612a42e4b37b5219fa2f4430a2f76ce79656038209b6f98
|
data/README.md
CHANGED
|
@@ -8,12 +8,10 @@ with other modules.
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
12
|
-
|
|
13
11
|
Install this gem on your development and CI/CD hosts:
|
|
14
12
|
|
|
15
13
|
```bash
|
|
16
|
-
/opt/puppetlabs/puppet/bin/gem install
|
|
14
|
+
/opt/puppetlabs/puppet/bin/gem install puppet-unit-tests
|
|
17
15
|
```
|
|
18
16
|
|
|
19
17
|
## Usage
|
|
@@ -23,7 +21,22 @@ classes, "define" for defined types. Create YAML files inside this directories
|
|
|
23
21
|
with usecases and expected results.
|
|
24
22
|
|
|
25
23
|
TODO: write a minimal example here and create an "examples" directory.
|
|
26
|
-
|
|
24
|
+
|
|
25
|
+
Add these lines to your Rakefile:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require 'puppet_unit_tests/rake_task'
|
|
29
|
+
PuppetUnitTests::RakeTask.new
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
TODO: how to customize task name
|
|
33
|
+
|
|
34
|
+
Run tests with:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
rake test
|
|
38
|
+
```
|
|
39
|
+
|
|
27
40
|
TODO: example CI/CD with Laminar?
|
|
28
41
|
|
|
29
42
|
## Development
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Puppet::Functions.create_function(:'test_data') do
|
|
4
|
+
dispatch :test_data do
|
|
5
|
+
param 'Struct[{uri=>String[1]}]', :options
|
|
6
|
+
param 'Puppet::LookupContext', :context
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
argument_mismatch :missing_uri do
|
|
10
|
+
param 'Hash', :options
|
|
11
|
+
param 'Puppet::LookupContext', :context
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_data(options, _context)
|
|
15
|
+
uri = options['uri']
|
|
16
|
+
hiera_data = Thread.current[:hiera_data]
|
|
17
|
+
return {} unless hiera_data
|
|
18
|
+
|
|
19
|
+
hiera_data[uri] || {}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def missing_uri(_options, _context)
|
|
23
|
+
"one of 'uri' or 'uris' must be declared in hiera.yaml " \
|
|
24
|
+
'when using this data_hash function.'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'rainbow'
|
|
4
|
+
|
|
3
5
|
require_relative "test_environment"
|
|
4
6
|
require_relative "test_data"
|
|
5
7
|
|
|
6
8
|
module PuppetUnitTests
|
|
7
9
|
# Test launcher.
|
|
8
10
|
class Runner
|
|
9
|
-
def initialize
|
|
11
|
+
def initialize(assets_dir = nil)
|
|
10
12
|
@env = nil
|
|
13
|
+
@assets_dir = assets_dir || File.realpath(
|
|
14
|
+
File.join(__dir__, '..', '..', 'assets')
|
|
15
|
+
)
|
|
16
|
+
@env_dir = nil
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
def run
|
|
@@ -31,23 +37,37 @@ module PuppetUnitTests
|
|
|
31
37
|
all_errors
|
|
32
38
|
end
|
|
33
39
|
|
|
40
|
+
def format_errors(errors)
|
|
41
|
+
errors.each do |puppet_obj, usecases|
|
|
42
|
+
puts puppet_obj
|
|
43
|
+
usecases.each do |uc_name, uc_errors|
|
|
44
|
+
puts " #{uc_name}:"
|
|
45
|
+
uc_errors.each do |err|
|
|
46
|
+
puts Rainbow(" #{err}").red
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
34
52
|
private
|
|
35
53
|
|
|
36
54
|
def setup
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
@env_dir = Dir.mktmpdir('puppet-test-env')
|
|
56
|
+
FileUtils.mkdir(File.join(@env_dir, 'modules'))
|
|
57
|
+
FileUtils.copy_entry(
|
|
58
|
+
File.join(@assets_dir, 'test-env'),
|
|
59
|
+
@env_dir
|
|
60
|
+
)
|
|
61
|
+
FileUtils.ln_s(Dir.pwd, File.join(@env_dir, 'modules'))
|
|
42
62
|
@env = TestEnvironment.new do |e|
|
|
43
|
-
e.environmentpath =
|
|
44
|
-
e.hiera_config = "
|
|
45
|
-
e.modulepath = "
|
|
63
|
+
e.environmentpath = @env_dir
|
|
64
|
+
e.hiera_config = File.join(@env_dir, "hiera.yaml")
|
|
65
|
+
e.modulepath = File.join(@env_dir, "modules")
|
|
46
66
|
end
|
|
47
67
|
end
|
|
48
68
|
|
|
49
69
|
def teardown
|
|
50
|
-
|
|
70
|
+
FileUtils.rmtree(@env_dir) if @env_dir
|
|
51
71
|
end
|
|
52
72
|
end
|
|
53
73
|
end
|
|
@@ -98,7 +98,9 @@ module PuppetUnitTests
|
|
|
98
98
|
[settings[:modulepath]],
|
|
99
99
|
Puppet::Node::Environment::NO_MANIFEST
|
|
100
100
|
)
|
|
101
|
-
loader = Puppet::Environments::
|
|
101
|
+
loader = Puppet::Environments::StaticDirectory.new(
|
|
102
|
+
env.name, settings[:environmentpath], env
|
|
103
|
+
)
|
|
102
104
|
Puppet.push_context(
|
|
103
105
|
{
|
|
104
106
|
environments: loader,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puppet-unit-tests
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arlo le Rouge
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '8.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rainbow
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
26
40
|
description: |
|
|
27
41
|
Describe environment (facts, Hiera data, etc.) and expected result (error,
|
|
28
42
|
resource in catalog, or resource not in catalog). Use stubs that may be shared
|
|
@@ -37,6 +51,8 @@ files:
|
|
|
37
51
|
- CODE_OF_CONDUCT.md
|
|
38
52
|
- README.md
|
|
39
53
|
- Rakefile
|
|
54
|
+
- assets/test-env/hiera.yaml
|
|
55
|
+
- assets/test-env/lib/puppet/functions/test_data.rb
|
|
40
56
|
- lib/puppet_unit_tests.rb
|
|
41
57
|
- lib/puppet_unit_tests/fake_facter.rb
|
|
42
58
|
- lib/puppet_unit_tests/rake_task.rb
|