onceover 3.9.0 → 3.10.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
  SHA1:
3
- metadata.gz: a37e753c95878c5de3f89a71d73e97b835e3ee54
4
- data.tar.gz: 5a71d30c65ef86e645110719ef752ad6306c99bd
3
+ metadata.gz: c14126b8e9eacece852e8c46c72f444cc44c1922
4
+ data.tar.gz: a378a1096ca8d649bd63b25e81cc5d782d4fe618
5
5
  SHA512:
6
- metadata.gz: 61c0d522ccd4864f4bb224a6a60560f8c3852eb2037472d727b73b768132665bf137277248e59bac088ddedcb3eac421af30598e8830db619df9473ee3e69c5d
7
- data.tar.gz: 56b657a2e74bb3344cb88785024afd4e977d74a04dbd1690c33e497157a2fe6c993b4b720e8c01c1347116e8e8d7e20856157bc9c9c9481241428c09bd4af697
6
+ metadata.gz: 379f509f4a9f6a249cc40a771b01979d6416f33fc862e2fa046a8a8b8d788592d6120c853fbdd4aaca50269dd10077c1e596f887a951f116e9fb04b0d331c3df
7
+ data.tar.gz: 5e62b583ce26d0092e49d9374eaa98b940a5e281686538e4f93cae43a135cdf5d834b52a9c838da771b1a9089c340dc9ad935b9f931f21a8a8643d8547b916b4
@@ -8,7 +8,17 @@ cache:
8
8
  script: bundle exec rake full_tests
9
9
  bundler_args: --path vendor/bundle
10
10
 
11
- rvm:
12
- - 2.3.8
13
- - 2.4.4
14
- - 2.5.3
11
+ matrix:
12
+ include:
13
+ # 2016.x -> 2017.2
14
+ - rvm: 2.1.9
15
+ env: PUPPET_VERSION="~>4.0"
16
+
17
+ # 2017.3 -> 2018.1
18
+ - rvm: 2.4.4
19
+ env: PUPPET_VERSION="~>5.0"
20
+
21
+ # 2019.0 -> now
22
+ - rvm: 2.5.1
23
+ env: PUPPET_VERSION="~>6.0"
24
+
data/Gemfile CHANGED
@@ -2,6 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ if ENV['PUPPET_VERSION']
6
+ gem 'puppet', ENV['PUPPET_VERSION']
7
+ end
8
+
5
9
  # Evaluate Gemfile.local if it exists
6
10
  if File.exists? "#{__FILE__}.local"
7
11
  eval(File.read("#{__FILE__}.local"), binding)
data/README.md CHANGED
@@ -108,8 +108,8 @@ Why an array of hashes? Well, that is so that we can refer to the same node or n
108
108
  In the example below we have referred to `centos6a` and `centos7b` in all of our tests as they are in `all_nodes`, `non_windows_servers` and `centos_severs`. However we have *left the more specific references to last*. This is because entries in the test_matrix will override entries above them if applicable. Meaning that we are still only testing each class on the two Centos servers once (Because the gem does de-duplication before running the tests), but also making sure we run `roles::frontend_webserver` twice before checking for idempotency.
109
109
 
110
110
  **functions** In this section we can add functions that we want to mock when running spec tests. Each function takes the following arguments:
111
- - **type** *statement or rvalue*
112
- - **returns** *Optional: A value to return*
111
+
112
+ - **returns** *Optional: A value to return*
113
113
 
114
114
  **before and after conditions** We can set `before` and `after` blocks before each spec test. These are usually used when the functions to stub are conditional: stub functionx if the OS is windows, stub functiony if the fact java_installed is true. The facts are available through the `node_facts` hash and the trusted facts as `trusted_facts`.
115
115
 
@@ -196,8 +196,9 @@ test_matrix:
196
196
 
197
197
  functions:
198
198
  query_resources:
199
- type: rvalue
200
199
  returns: []
200
+ profile::custom_function:
201
+ returns: ["one", "two"]
201
202
 
202
203
  opts:
203
204
  :facts_dirs:
@@ -621,3 +622,4 @@ Cheers to all of those who helped out:
621
622
  - @tabakhase
622
623
  - @binford2k
623
624
  - @raphink
625
+ - @tequeter
@@ -37,11 +37,6 @@ Feature: Run rspec and acceptance test suites
37
37
  And I run onceover command "run spec --force"
38
38
  Then I should see message pattern "Overwriting local modifications"
39
39
 
40
- Scenario: Run advanced spec tests
41
- Given control repo "puppet_controlrepo"
42
- When I run onceover command "run spec"
43
- Then I should not see any errors
44
-
45
40
  Scenario: Check that control_branch functionality works
46
41
  Given initialized control repo "control_branch"
47
42
  When I run onceover command "run spec"
@@ -49,5 +44,16 @@ Feature: Run rspec and acceptance test suites
49
44
 
50
45
  Scenario: Mocking functions should work and return the correct data types
51
46
  Given control repo "function_mocking"
52
- When I run onceover command "run spec"
47
+ When I run onceover command "run spec" with class "role::test_data_return"
53
48
  Then I should not see any errors
49
+
50
+ Scenario: Mocking functions that use the new :: pathing
51
+ Given control repo "function_mocking"
52
+ When I run onceover command "run spec" with class "role::test_new_functions"
53
+ Then I should not see any errors
54
+
55
+ # This test is a full test using my controlrepo. It should remain at the end because it takes ages
56
+ Scenario: Run advanced spec tests
57
+ Given control repo "puppet_controlrepo"
58
+ When I run onceover command "run spec"
59
+ Then I should not see any errors
@@ -31,6 +31,12 @@ When(/^I run onceover command "([^"]*)"$/) do |command|
31
31
  @cmd.run
32
32
  end
33
33
 
34
+ When(/^I run onceover command "([^"]*)" with class "([^"]*)"$/) do |command, cls|
35
+ @cmd.command = "#{command} --classes #{cls}"
36
+ puts @cmd
37
+ @cmd.run
38
+ end
39
+
34
40
  Then(/^I see help for commands: "([^"]*)"$/) do |commands|
35
41
  # Get chunk of output between COMMANDS and OPTION, there should be help section
36
42
  commands_help = @cmd.output[/COMMANDS(.*)OPTIONS/m, 1]
@@ -71,6 +71,11 @@ class Onceover
71
71
  @skip_r10k = opts[:skip_r10k] ? true : false
72
72
  @force = opts[:force] || false
73
73
 
74
+ # Validate the mock_functions
75
+ if @mock_functions && @mock_functions.any? { |name, details| details.has_key? 'type' }
76
+ logger.warn "The 'type' key for mocked functions is deprecated and will be ignored, please remove it."
77
+ end
78
+
74
79
  # Loop over all of the items in the test matrix and add those as test
75
80
  # objects to the list of tests
76
81
  config['test_matrix'].each do |test_hash|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "onceover"
7
- s.version = "3.9.0"
7
+ s.version = "3.10.0"
8
8
  s.authors = ["Dylan Ratcliffe"]
9
9
  s.email = ["dylan.ratcliffe@puppet.com"]
10
10
  s.homepage = "https://github.com/dylanratcliffe/onceover"
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0"
24
24
  s.add_runtime_dependency 'parallel_tests', ">= 2.0.0"
25
25
  s.add_runtime_dependency 'puppetlabs_spec_helper', ">= 0.4.0"
26
- s.add_runtime_dependency 'rspec-puppet-utils', '>= 2.0.0'
27
26
  s.add_runtime_dependency 'rspec', '>= 3.0.0'
28
27
  s.add_runtime_dependency 'r10k', '>=2.1.0'
29
28
  s.add_runtime_dependency 'puppet', '>=3.4.0'
@@ -2,16 +2,3 @@ forge "http://forge.puppetlabs.com"
2
2
  #
3
3
  # I want to download some modules to check if r10k feature in Onceover works correctly.
4
4
  #
5
-
6
- # Versions should be updated to be the latest at the time you start
7
- mod "puppetlabs/stdlib", '4.11.0'
8
-
9
- # Modules from Git
10
- # Examples: https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd#examples
11
- mod 'apache',
12
- :git => 'https://github.com/puppetlabs/puppetlabs-apache',
13
- :commit => '83401079053dca11d61945bd9beef9ecf7576cbf'
14
-
15
- #mod 'apache',
16
- # :git => 'https://github.com/puppetlabs/puppetlabs-apache',
17
- # :branch => 'docs_experiment'
@@ -0,0 +1,5 @@
1
+ function profile::fail_puppet (
2
+ String $message,
3
+ ) {
4
+ fail($message)
5
+ }
@@ -0,0 +1,9 @@
1
+ Puppet::Functions.create_function(:'profile::fail_ruby') do
2
+ dispatch :fail do
3
+ param 'String', :message
4
+ end
5
+
6
+ def fail(message)
7
+ call_function('fail', message)
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # Class: profile::base
2
+ #
3
+ #
4
+ class profile::base {
5
+ # This function should fail unless it is mocked
6
+ profile::fail_puppet('Puppet language function still failed!')
7
+
8
+ # So should this
9
+ profile::fail_ruby('Ruby function failed!')
10
+ }
@@ -1,19 +1,19 @@
1
1
  # == Class: role::test_functions
2
2
  #
3
- class role::test_functions {
4
- unless string('foo') =~ String {
3
+ class role::test_data_return {
4
+ unless return_string() =~ String {
5
5
  fail('string() did not return a string')
6
6
  }
7
- unless number('foo') =~ Numeric {
7
+ unless return_number('foo','bar') =~ Numeric {
8
8
  fail('string() did not return a string')
9
9
  }
10
- unless boolean('foo') =~ Boolean {
10
+ unless return_boolean('foo') =~ Boolean {
11
11
  fail('string() did not return a string')
12
12
  }
13
- unless array('foo') =~ Array {
13
+ unless return_array('foo') =~ Array {
14
14
  fail('string() did not return a string')
15
15
  }
16
- unless hash('foo') =~ Hash {
16
+ unless return_hash('foo') =~ Hash {
17
17
  fail('string() did not return a string')
18
18
  }
19
19
  }
@@ -0,0 +1,12 @@
1
+ # Class: role::test_new_functions
2
+ #
3
+ #
4
+ class role::test_new_functions {
5
+
6
+ # This function should fail unless it is mocked
7
+ profile::fail_puppet('Puppet language function still failed!')
8
+
9
+ # So should this
10
+ profile::fail_ruby('Ruby function failed!')
11
+
12
+ }
@@ -1,6 +1,6 @@
1
1
  # Classes to be tested
2
2
  classes:
3
- - role::test_functions
3
+ - /role::/
4
4
 
5
5
  # Nodes to tests classes on, this refers to a 'factset' or 'nodeset'
6
6
  # depending on whether you are running 'spec' or 'acceptance' tests
@@ -22,25 +22,31 @@ test_matrix:
22
22
  tests: 'spec'
23
23
 
24
24
  functions:
25
- string:
25
+ return_string:
26
26
  type: rvalue
27
27
  returns: string
28
- number:
28
+ return_number:
29
29
  type: rvalue
30
30
  returns: 400
31
- boolean:
31
+ return_boolean:
32
32
  type: rvalue
33
33
  returns: true
34
- array:
34
+ return_array:
35
35
  type: rvalue
36
36
  returns:
37
37
  - 1
38
38
  - 2
39
39
  - 3
40
- hash:
40
+ return_hash:
41
41
  type: rvalue
42
42
  returns:
43
43
  foo: bar
44
+ profile::fail_puppet:
45
+ type: rvalue
46
+ returns: null
47
+ profile::fail_ruby:
48
+ type: rvalue
49
+ returns: null
44
50
 
45
51
  opts:
46
52
  :debug: true
@@ -1,5 +1,18 @@
1
+ # Yes it's strange that we have to call `RSpec.configure` more than once. The
2
+ # reason we are doing this is to silence the incredibly annoying warning:
3
+ #
4
+ # puppetlabs_spec_helper: defaults `mock_with` to `:mocha`
5
+ #
6
+ # In order to do this we have configure the
7
+ # mocking, THEN require puppetlabs_spec_helper.
8
+ #
9
+ # Yes, I know. Someone buy me a 🍺 for fixing this.
10
+ #
11
+ RSpec.configure do |c|
12
+ c.mock_with :mocha
13
+ end
14
+
1
15
  require 'puppetlabs_spec_helper/module_spec_helper'
2
- require 'rspec-puppet-utils'
3
16
  require 'rspec_junit_formatter'
4
17
 
5
18
  RSpec.configure do |c|
@@ -3,19 +3,6 @@ require 'spec_helper'
3
3
  <% test.classes.each do |cls| -%>
4
4
  describe "<%= cls.name %>" do
5
5
 
6
- <% if @mock_functions -%>
7
- <% @mock_functions.each do |function,params| -%>
8
- <% if params['type'] == 'statement' -%>
9
- MockFunction.new('<%= function %>', {:type => :statement})
10
- <% else -%>
11
- let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f|
12
- f.stubbed.returns(<%= params['returns'].inspect %>)
13
- }
14
- }
15
- <% end -%>
16
-
17
- <% end -%>
18
- <% end -%>
19
6
  <% test.nodes.each do |node| -%>
20
7
  context "using fact set <%= node.name %>" do
21
8
  node_facts = <%= node.fact_set %>
@@ -31,6 +18,17 @@ let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f|
31
18
  <% end -%>
32
19
  end
33
20
  <% end -%>
21
+
22
+ <% if @mock_functions -%>
23
+ # Create a from_json function so that we can parse the output of json for mocked functions
24
+ before :each do
25
+ Puppet::Parser::Functions.newfunction(:from_json, :type => :rvalue) { |args|
26
+ require 'json'
27
+ JSON.parse(args[0])
28
+ }
29
+ end
30
+ <% end -%>
31
+
34
32
  <% if @after_conditions -%>
35
33
  after :each do
36
34
  <% @after_conditions.each do |function| -%>
@@ -38,15 +36,26 @@ let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f|
38
36
  <% end -%>
39
37
  end
40
38
  <% end -%>
41
- <% if pre_condition -%>
42
39
  let(:pre_condition) {
43
40
  pp = <%= '<<' %>-END
44
41
  $onceover_class = '<%= cls.name %>'
45
- $onceover_node = '<%= node.name %>'
46
- <%= pre_condition.chomp %>
42
+ $onceover_node = '<%= node.name %>'
43
+
44
+ # Begin user-specified pre_condition
45
+ <%= (pre_condition || "").chomp %>
46
+ # End user-specified pre_condition
47
+
48
+ <% if @mock_functions -%>
49
+ <% require 'json' -%>
50
+ # Mocking functions
51
+ <% @mock_functions.each do |function,params| -%>
52
+ function <%= function %> (*$args) { from_json('<%= params['returns'].to_json %>') }
53
+ <% end -%>
54
+ <% end -%>
55
+
47
56
  END
48
57
  }
49
- <% end -%>
58
+
50
59
  it { should compile }
51
60
  end
52
61
  <% end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onceover
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Ratcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-24 00:00:00.000000000 Z
11
+ date: 2019-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.0
83
- - !ruby/object:Gem::Dependency
84
- name: rspec-puppet-utils
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 2.0.0
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 2.0.0
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rspec
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -405,12 +391,14 @@ files:
405
391
  - spec/fixtures/controlrepos/control_branch/Puppetfile
406
392
  - spec/fixtures/controlrepos/control_branch/environment.conf
407
393
  - spec/fixtures/controlrepos/function_mocking/.gitignore
408
- - spec/fixtures/controlrepos/function_mocking/Gemfile
409
394
  - spec/fixtures/controlrepos/function_mocking/Puppetfile
410
395
  - spec/fixtures/controlrepos/function_mocking/Rakefile
411
396
  - spec/fixtures/controlrepos/function_mocking/environment.conf
412
- - spec/fixtures/controlrepos/function_mocking/manifests/site.pp
413
- - spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_functions.pp
397
+ - spec/fixtures/controlrepos/function_mocking/site/profile/functions/fail_puppet.pp
398
+ - spec/fixtures/controlrepos/function_mocking/site/profile/lib/puppet/functions/profile/fail_ruby.rb
399
+ - spec/fixtures/controlrepos/function_mocking/site/profile/manifests/base.pp
400
+ - spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp
401
+ - spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_new_functions.pp
414
402
  - spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml
415
403
  - spec/fixtures/controlrepos/minimal/environment.conf
416
404
  - spec/onceover/controlrepo_spec.rb
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'onceover'
@@ -1,32 +0,0 @@
1
- ## site.pp ##
2
-
3
- # This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point
4
- # used when an agent connects to a master and asks for an updated configuration.
5
- #
6
- # Global objects like filebuckets and resource defaults should go in this file,
7
- # as should the default node definition. (The default node can be omitted
8
- # if you use the console and don't define any other nodes in site.pp. See
9
- # http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
10
- # node definitions.)
11
-
12
- ## Active Configurations ##
13
-
14
- # Disable filebucket by default for all File resources:
15
- #https://docs.puppet.com/pe/2015.3/release_notes.html#filebucket-resource-no-longer-created-by-default
16
- File { backup => false }
17
-
18
- # DEFAULT NODE
19
- # Node definitions in this file are merged with node data from the console. See
20
- # http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
21
- # node definitions.
22
-
23
- # The default node definition matches any node lacking a more specific node
24
- # definition. If there are no other nodes in this file, classes declared here
25
- # will be included in every node's catalog, *in addition* to any classes
26
- # specified in the console for that node.
27
-
28
- node default {
29
- # This is where you can declare classes for all nodes.
30
- # Example:
31
- # class { 'my_class': }
32
- }