puppet-unit-tests 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db3e14f98dbe5bcd033b2f0967db022a10d59a4df551d1b2fd196e82c77c4592
4
- data.tar.gz: 420e1254f3b4b1254bdf3bf2a40c21e6ff8407e29c2ee2a0b0bff0ca3b664aed
3
+ metadata.gz: 1d7ab89c77ec25cf0bcb946265debd9067ce1a30fc28b1ae42de86e482858056
4
+ data.tar.gz: 3e2040483fded2adbb3cce542dbe83b760c8d01bf6805e11265cfbabfa615cc5
5
5
  SHA512:
6
- metadata.gz: c13c1ffa6ea8d3b68851d82eb77bc5048f6bd332ccb22baf05ee935f50d002b7b7f6135b96fbd6b77bb79324e0a64c3283c06ad2210fdfa6d81dfe2549f000df
7
- data.tar.gz: fd1b2728f3db290f0a5c55b41398b749b3b0702102e277c6733d603000c595f1322d8188c58b0cd0bc9f3120e136f86464f117e019798a5c9edfbbdbe01bc464
6
+ metadata.gz: c9e3892eaa8f0ffd9a1f284466947ad0b1992a39f37ed4b5b52c02945f993ab0c5a8ed936cd4a80fb0ea608946a983b907968ab2e81402925ac0f91c78669bd0
7
+ data.tar.gz: 71bac823f2808ace6ea055e67a74e3c0248eb42c0068e1f65fd7a370981ee0907d1e18730e5c15ab0a8702215d31fda908d2dac6053912d6af55f42d92d10697
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 UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- TODO: write rake task
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,12 @@
1
+ ---
2
+ version: 5
3
+ defaults:
4
+ datadir: 'data'
5
+ data_hash: 'test_data'
6
+ # data_hash: 'yaml_data'
7
+
8
+ hierarchy:
9
+ - name: "test Hiera data"
10
+ uris:
11
+ - usecase
12
+ - global
@@ -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
@@ -6,8 +6,12 @@ require_relative "test_data"
6
6
  module PuppetUnitTests
7
7
  # Test launcher.
8
8
  class Runner
9
- def initialize
9
+ def initialize(assets_dir = nil)
10
10
  @env = nil
11
+ @assets_dir = assets_dir || File.realpath(
12
+ File.join(__dir__, '..', '..', 'assets')
13
+ )
14
+ @env_dir = nil
11
15
  end
12
16
 
13
17
  def run
@@ -34,20 +38,22 @@ module PuppetUnitTests
34
38
  private
35
39
 
36
40
  def setup
37
- # TODO: create temporary environment directory
38
- # TODO: create modules directory
39
- # TODO: create module with test Hiera provider
40
- # TODO: create hiera config file
41
- # TODO: create symlink to tested module
41
+ @env_dir = Dir.mktmpdir('puppet-test-env')
42
+ FileUtils.mkdir(File.join(@env_dir, 'modules'))
43
+ FileUtils.copy_entry(
44
+ File.join(@assets_dir, 'test-env'),
45
+ @env_dir
46
+ )
47
+ FileUtils.ln_s(Dir.pwd, File.join(@env_dir, 'modules'))
42
48
  @env = TestEnvironment.new do |e|
43
- e.environmentpath = "tests"
44
- e.hiera_config = "tests/hiera.yaml"
45
- e.modulepath = "tests/modules"
49
+ e.environmentpath = @env_dir
50
+ e.hiera_config = File.join(@env_dir, "hiera.yaml")
51
+ e.modulepath = File.join(@env_dir, "modules")
46
52
  end
47
53
  end
48
54
 
49
55
  def teardown
50
- # TODO: remove temporary environment directory
56
+ FileUtils.rmtree(@env_dir) if @env_dir
51
57
  end
52
58
  end
53
59
  end
@@ -98,7 +98,9 @@ module PuppetUnitTests
98
98
  [settings[:modulepath]],
99
99
  Puppet::Node::Environment::NO_MANIFEST
100
100
  )
101
- loader = Puppet::Environments::Static.new(env)
101
+ loader = Puppet::Environments::StaticDirectory.new(
102
+ env.name, settings[:environmentpath], env
103
+ )
102
104
  Puppet.push_context(
103
105
  {
104
106
  environments: loader,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PuppetUnitTests
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arlo le Rouge
@@ -37,6 +37,8 @@ files:
37
37
  - CODE_OF_CONDUCT.md
38
38
  - README.md
39
39
  - Rakefile
40
+ - assets/test-env/hiera.yaml
41
+ - assets/test-env/lib/puppet/functions/test_data.rb
40
42
  - lib/puppet_unit_tests.rb
41
43
  - lib/puppet_unit_tests/fake_facter.rb
42
44
  - lib/puppet_unit_tests/rake_task.rb