From 6bb2a8364c430594506e31a25f1f70ab7fb79202 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Mon, 4 Feb 2019 18:07:50 +0100 Subject: [PATCH 01/10] Added failing test for #197 --- features/run.feature | 18 +++++++---- features/step_definitions/common.rb | 6 ++++ .../function_mocking/manifests/site.pp | 32 ------------------- .../site/profile/functions/fail_puppet.pp | 5 +++ .../lib/puppet/functions/profile/fail_ruby.rb | 9 ++++++ .../site/profile/manifests/base.pp | 10 ++++++ ...{test_functions.pp => test_data_return.pp} | 2 +- .../site/role/manifests/test_new_functions.pp | 12 +++++++ .../function_mocking/spec/onceover.yaml | 8 ++++- 9 files changed, 62 insertions(+), 40 deletions(-) delete mode 100644 spec/fixtures/controlrepos/function_mocking/manifests/site.pp create mode 100644 spec/fixtures/controlrepos/function_mocking/site/profile/functions/fail_puppet.pp create mode 100644 spec/fixtures/controlrepos/function_mocking/site/profile/lib/puppet/functions/profile/fail_ruby.rb create mode 100644 spec/fixtures/controlrepos/function_mocking/site/profile/manifests/base.pp rename spec/fixtures/controlrepos/function_mocking/site/role/manifests/{test_functions.pp => test_data_return.pp} (93%) create mode 100644 spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_new_functions.pp diff --git a/features/run.feature b/features/run.feature index 61ad99c8..7130f0a6 100644 --- a/features/run.feature +++ b/features/run.feature @@ -37,11 +37,6 @@ Feature: Run rspec and acceptance test suites And I run onceover command "run spec --force" Then I should see message pattern "Overwriting local modifications" - Scenario: Run advanced spec tests - Given control repo "puppet_controlrepo" - When I run onceover command "run spec" - Then I should not see any errors - Scenario: Check that control_branch functionality works Given initialized control repo "control_branch" When I run onceover command "run spec" @@ -49,5 +44,16 @@ Feature: Run rspec and acceptance test suites Scenario: Mocking functions should work and return the correct data types Given control repo "function_mocking" - When I run onceover command "run spec" + When I run onceover command "run spec" with class "role::test_data_return" Then I should not see any errors + + Scenario: Mocking tunctions that use the new :: pathing + Given control repo "function_mocking" + When I run onceover command "run spec" with class "role::test_new_functions" + Then I should not see any errors + + # This test is a full test using my controlrepo. It should remain at the end because it takes ages + Scenario: Run advanced spec tests + Given control repo "puppet_controlrepo" + When I run onceover command "run spec" + Then I should not see any errors \ No newline at end of file diff --git a/features/step_definitions/common.rb b/features/step_definitions/common.rb index fbce4bc0..ace4b6a4 100644 --- a/features/step_definitions/common.rb +++ b/features/step_definitions/common.rb @@ -31,6 +31,12 @@ @cmd.run end +When(/^I run onceover command "([^"]*)" with class "([^"]*)"$/) do |command, cls| + @cmd.command = "#{command} --classes #{cls}" + puts @cmd + @cmd.run +end + Then(/^I see help for commands: "([^"]*)"$/) do |commands| # Get chunk of output between COMMANDS and OPTION, there should be help section commands_help = @cmd.output[/COMMANDS(.*)OPTIONS/m, 1] diff --git a/spec/fixtures/controlrepos/function_mocking/manifests/site.pp b/spec/fixtures/controlrepos/function_mocking/manifests/site.pp deleted file mode 100644 index 7059c8cd..00000000 --- a/spec/fixtures/controlrepos/function_mocking/manifests/site.pp +++ /dev/null @@ -1,32 +0,0 @@ -## site.pp ## - -# This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point -# used when an agent connects to a master and asks for an updated configuration. -# -# Global objects like filebuckets and resource defaults should go in this file, -# as should the default node definition. (The default node can be omitted -# if you use the console and don't define any other nodes in site.pp. See -# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on -# node definitions.) - -## Active Configurations ## - -# Disable filebucket by default for all File resources: -#https://docs.puppet.com/pe/2015.3/release_notes.html#filebucket-resource-no-longer-created-by-default -File { backup => false } - -# DEFAULT NODE -# Node definitions in this file are merged with node data from the console. See -# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on -# node definitions. - -# The default node definition matches any node lacking a more specific node -# definition. If there are no other nodes in this file, classes declared here -# will be included in every node's catalog, *in addition* to any classes -# specified in the console for that node. - -node default { - # This is where you can declare classes for all nodes. - # Example: - # class { 'my_class': } -} diff --git a/spec/fixtures/controlrepos/function_mocking/site/profile/functions/fail_puppet.pp b/spec/fixtures/controlrepos/function_mocking/site/profile/functions/fail_puppet.pp new file mode 100644 index 00000000..e1b0d0b2 --- /dev/null +++ b/spec/fixtures/controlrepos/function_mocking/site/profile/functions/fail_puppet.pp @@ -0,0 +1,5 @@ +function profile::fail_puppet ( + String $message, +) { + fail($message) +} diff --git a/spec/fixtures/controlrepos/function_mocking/site/profile/lib/puppet/functions/profile/fail_ruby.rb b/spec/fixtures/controlrepos/function_mocking/site/profile/lib/puppet/functions/profile/fail_ruby.rb new file mode 100644 index 00000000..1e2174fe --- /dev/null +++ b/spec/fixtures/controlrepos/function_mocking/site/profile/lib/puppet/functions/profile/fail_ruby.rb @@ -0,0 +1,9 @@ +Puppet::Functions.create_function(:'profile::fail_ruby') do + dispatch :fail do + param 'String', :message + end + + def fail(message) + call_function('fail', message) + end +end \ No newline at end of file diff --git a/spec/fixtures/controlrepos/function_mocking/site/profile/manifests/base.pp b/spec/fixtures/controlrepos/function_mocking/site/profile/manifests/base.pp new file mode 100644 index 00000000..9f09dd91 --- /dev/null +++ b/spec/fixtures/controlrepos/function_mocking/site/profile/manifests/base.pp @@ -0,0 +1,10 @@ +# Class: profile::base +# +# +class profile::base { + # This function should fail unless it is mocked + profile::fail_puppet('Puppet language function still failed!') + + # So should this + profile::fail_ruby('Ruby function failed!') +} diff --git a/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_functions.pp b/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp similarity index 93% rename from spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_functions.pp rename to spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp index 468a732e..38818a56 100644 --- a/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_functions.pp +++ b/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp @@ -1,6 +1,6 @@ # == Class: role::test_functions # -class role::test_functions { +class role::test_data_return { unless string('foo') =~ String { fail('string() did not return a string') } diff --git a/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_new_functions.pp b/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_new_functions.pp new file mode 100644 index 00000000..718f6609 --- /dev/null +++ b/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_new_functions.pp @@ -0,0 +1,12 @@ +# Class: role::test_new_functions +# +# +class role::test_new_functions { + + # This function should fail unless it is mocked + profile::fail_puppet('Puppet language function still failed!') + + # So should this + profile::fail_ruby('Ruby function failed!') + +} diff --git a/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml b/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml index 8b15415b..aba87ba9 100644 --- a/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml +++ b/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml @@ -1,6 +1,6 @@ # Classes to be tested classes: - - role::test_functions + - /role::/ # Nodes to tests classes on, this refers to a 'factset' or 'nodeset' # depending on whether you are running 'spec' or 'acceptance' tests @@ -41,6 +41,12 @@ functions: type: rvalue returns: foo: bar + profile::fail_puppet: + type: rvalue + returns: null + profile::fail_ruby: + type: rvalue + returns: null opts: :debug: true From cd97c3067a4ad0098df0f3174560f8879f672dc5 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Mon, 4 Feb 2019 18:19:21 +0100 Subject: [PATCH 02/10] Added proper symbol handling #197 This means that if you want to use a function that has a `::` in it, you don't have to do any weird quoting --- templates/test_spec.rb.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/test_spec.rb.erb b/templates/test_spec.rb.erb index 281d1e2b..c00cb53d 100644 --- a/templates/test_spec.rb.erb +++ b/templates/test_spec.rb.erb @@ -8,7 +8,7 @@ describe "<%= cls.name %>" do <% if params['type'] == 'statement' -%> MockFunction.new('<%= function %>', {:type => :statement}) <% else -%> -let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f| +let!(<%= function.to_sym.inspect %>) { MockFunction.new('<%= function %>') { |f| f.stubbed.returns(<%= params['returns'].inspect %>) } } From f905a434e1924a811f41353a905cf1acb5a6165e Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Mon, 4 Feb 2019 18:19:53 +0100 Subject: [PATCH 03/10] Removed extra test files to speed up testing --- spec/fixtures/controlrepos/function_mocking/Gemfile | 3 --- .../controlrepos/function_mocking/Puppetfile | 13 ------------- 2 files changed, 16 deletions(-) delete mode 100644 spec/fixtures/controlrepos/function_mocking/Gemfile diff --git a/spec/fixtures/controlrepos/function_mocking/Gemfile b/spec/fixtures/controlrepos/function_mocking/Gemfile deleted file mode 100644 index 1d7df032..00000000 --- a/spec/fixtures/controlrepos/function_mocking/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'https://rubygems.org' - -gem 'onceover' diff --git a/spec/fixtures/controlrepos/function_mocking/Puppetfile b/spec/fixtures/controlrepos/function_mocking/Puppetfile index 9f94f115..2321c59c 100644 --- a/spec/fixtures/controlrepos/function_mocking/Puppetfile +++ b/spec/fixtures/controlrepos/function_mocking/Puppetfile @@ -2,16 +2,3 @@ forge "http://forge.puppetlabs.com" # # I want to download some modules to check if r10k feature in Onceover works correctly. # - -# Versions should be updated to be the latest at the time you start -mod "puppetlabs/stdlib", '4.11.0' - -# Modules from Git -# Examples: https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd#examples -mod 'apache', - :git => 'https://github.com/puppetlabs/puppetlabs-apache', - :commit => '83401079053dca11d61945bd9beef9ecf7576cbf' - -#mod 'apache', -# :git => 'https://github.com/puppetlabs/puppetlabs-apache', -# :branch => 'docs_experiment' From 3a54a1bd60da0d7e5c1ec5afb68997715b83439d Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Mon, 4 Feb 2019 18:33:21 +0100 Subject: [PATCH 04/10] Configured mocking before requiring spec_helper. Fixes #174 --- templates/spec_helper.rb.erb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/templates/spec_helper.rb.erb b/templates/spec_helper.rb.erb index 849b16d4..64e3337a 100644 --- a/templates/spec_helper.rb.erb +++ b/templates/spec_helper.rb.erb @@ -1,5 +1,21 @@ -require 'puppetlabs_spec_helper/module_spec_helper' +# Yes this is a strage order of requring things. It's also strange that we have +# to call `RSpec.configure` more than once. The reason we are doing this is to +# silence the incredibly annoying warning: +# +# puppetlabs_spec_helper: defaults `mock_with` to `:mocha` +# +# In order to do this we have to require rspec-puppet-utils, then configure the +# mocking, THEN require puppetlabs_spec_helper. +# +# Yes, I know. Someone buy me a 🍺 for fixing this. +# require 'rspec-puppet-utils' + +RSpec.configure do |c| + c.mock_with :mocha +end + +require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec_junit_formatter' RSpec.configure do |c| From c61f37a3aca0d42e0ceea93ff6a779afdbf4f0ff Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 5 Feb 2019 19:42:37 +0100 Subject: [PATCH 05/10] Changed function mocking method to use Puppet language instead of ruby Fixes #197 --- features/run.feature | 2 +- onceover.gemspec | 1 - .../site/role/manifests/test_data_return.pp | 10 ++--- .../function_mocking/spec/onceover.yaml | 10 ++--- templates/test_spec.rb.erb | 43 +++++++++++-------- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/features/run.feature b/features/run.feature index 7130f0a6..6cfa0b9e 100644 --- a/features/run.feature +++ b/features/run.feature @@ -47,7 +47,7 @@ Feature: Run rspec and acceptance test suites When I run onceover command "run spec" with class "role::test_data_return" Then I should not see any errors - Scenario: Mocking tunctions that use the new :: pathing + Scenario: Mocking functions that use the new :: pathing Given control repo "function_mocking" When I run onceover command "run spec" with class "role::test_new_functions" Then I should not see any errors diff --git a/onceover.gemspec b/onceover.gemspec index 3fc8bc8b..cbe1d409 100644 --- a/onceover.gemspec +++ b/onceover.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0" s.add_runtime_dependency 'parallel_tests', ">= 2.0.0" s.add_runtime_dependency 'puppetlabs_spec_helper', ">= 0.4.0" - s.add_runtime_dependency 'rspec-puppet-utils', '>= 2.0.0' s.add_runtime_dependency 'rspec', '>= 3.0.0' s.add_runtime_dependency 'r10k', '>=2.1.0' s.add_runtime_dependency 'puppet', '>=3.4.0' diff --git a/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp b/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp index 38818a56..65226060 100644 --- a/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp +++ b/spec/fixtures/controlrepos/function_mocking/site/role/manifests/test_data_return.pp @@ -1,19 +1,19 @@ # == Class: role::test_functions # class role::test_data_return { - unless string('foo') =~ String { + unless return_string() =~ String { fail('string() did not return a string') } - unless number('foo') =~ Numeric { + unless return_number('foo','bar') =~ Numeric { fail('string() did not return a string') } - unless boolean('foo') =~ Boolean { + unless return_boolean('foo') =~ Boolean { fail('string() did not return a string') } - unless array('foo') =~ Array { + unless return_array('foo') =~ Array { fail('string() did not return a string') } - unless hash('foo') =~ Hash { + unless return_hash('foo') =~ Hash { fail('string() did not return a string') } } diff --git a/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml b/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml index aba87ba9..d5037237 100644 --- a/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml +++ b/spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml @@ -22,22 +22,22 @@ test_matrix: tests: 'spec' functions: - string: + return_string: type: rvalue returns: string - number: + return_number: type: rvalue returns: 400 - boolean: + return_boolean: type: rvalue returns: true - array: + return_array: type: rvalue returns: - 1 - 2 - 3 - hash: + return_hash: type: rvalue returns: foo: bar diff --git a/templates/test_spec.rb.erb b/templates/test_spec.rb.erb index c00cb53d..08283f62 100644 --- a/templates/test_spec.rb.erb +++ b/templates/test_spec.rb.erb @@ -3,19 +3,6 @@ require 'spec_helper' <% test.classes.each do |cls| -%> describe "<%= cls.name %>" do -<% if @mock_functions -%> -<% @mock_functions.each do |function,params| -%> -<% if params['type'] == 'statement' -%> -MockFunction.new('<%= function %>', {:type => :statement}) -<% else -%> -let!(<%= function.to_sym.inspect %>) { MockFunction.new('<%= function %>') { |f| - f.stubbed.returns(<%= params['returns'].inspect %>) - } -} -<% end -%> - -<% end -%> -<% end -%> <% test.nodes.each do |node| -%> context "using fact set <%= node.name %>" do node_facts = <%= node.fact_set %> @@ -31,6 +18,17 @@ let!(<%= function.to_sym.inspect %>) { MockFunction.new('<%= function %>') { |f| <% end -%> end <% end -%> + +<% if @mock_functions -%> + # Create a from_json function so that we can parse the output of json for mocked functions + before :each do + Puppet::Parser::Functions.newfunction(:from_json, :type => :rvalue) { |args| + require 'json' + JSON.parse(args[0]) + } + end +<% end -%> + <% if @after_conditions -%> after :each do <% @after_conditions.each do |function| -%> @@ -38,15 +36,26 @@ let!(<%= function.to_sym.inspect %>) { MockFunction.new('<%= function %>') { |f| <% end -%> end <% end -%> -<% if pre_condition -%> let(:pre_condition) { pp = <%= '<<' %>-END $onceover_class = '<%= cls.name %>' -$onceover_node = '<%= node.name %>' -<%= pre_condition.chomp %> +$onceover_node = '<%= node.name %>' + +# Begin user-specified pre_condition +<%= (pre_condition || "").chomp %> +# End user-specified pre_condition + +<% if @mock_functions -%> +<% require 'json' -%> +# Mocking functions +<% @mock_functions.each do |function,params| -%> +function <%= function %> (*$args) { from_json('<%= params['returns'].to_json %>') } +<% end -%> +<% end -%> + END } -<% end -%> + it { should compile } end <% end -%> From 14afae7eaf4e44a956085274b13a2923eea1f194 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 5 Feb 2019 19:45:07 +0100 Subject: [PATCH 06/10] Removed spec_helper dependency --- templates/spec_helper.rb.erb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/templates/spec_helper.rb.erb b/templates/spec_helper.rb.erb index 64e3337a..58e04d65 100644 --- a/templates/spec_helper.rb.erb +++ b/templates/spec_helper.rb.erb @@ -1,16 +1,13 @@ -# Yes this is a strage order of requring things. It's also strange that we have -# to call `RSpec.configure` more than once. The reason we are doing this is to -# silence the incredibly annoying warning: +# Yes it's strange that we have to call `RSpec.configure` more than once. The +# reason we are doing this is to silence the incredibly annoying warning: # # puppetlabs_spec_helper: defaults `mock_with` to `:mocha` # -# In order to do this we have to require rspec-puppet-utils, then configure the +# In order to do this we have configure the # mocking, THEN require puppetlabs_spec_helper. # # Yes, I know. Someone buy me a 🍺 for fixing this. # -require 'rspec-puppet-utils' - RSpec.configure do |c| c.mock_with :mocha end From 9e14b38211d0d9000504bca1ae6adaac570a9f77 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 5 Feb 2019 20:11:36 +0100 Subject: [PATCH 07/10] Added puppet versions to test matrix --- .travis.yml | 5 +++++ Gemfile | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8072b27e..97e41102 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,11 @@ cache: script: bundle exec rake full_tests bundler_args: --path vendor/bundle +env: + - PUPPET_VERSION=~>4.0 + - PUPPET_VERSION=~>5.0 + - PUPPET_VERSION=~>6.0 + rvm: - 2.3.8 - 2.4.4 diff --git a/Gemfile b/Gemfile index 7a06a736..2b0cfd59 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,10 @@ source 'https://rubygems.org' gemspec +if ENV['PUPPET_VERSION'] + gem 'puppet', ENV['PUPPET_VERSION'] +end + # Evaluate Gemfile.local if it exists if File.exists? "#{__FILE__}.local" eval(File.read("#{__FILE__}.local"), binding) From 82339d41bd2781f1f63c44d179c6f982b63b033e Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 5 Feb 2019 20:13:57 +0100 Subject: [PATCH 08/10] Added quotes --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 97e41102..3f014892 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,9 @@ script: bundle exec rake full_tests bundler_args: --path vendor/bundle env: - - PUPPET_VERSION=~>4.0 - - PUPPET_VERSION=~>5.0 - - PUPPET_VERSION=~>6.0 + - PUPPET_VERSION="~>4.0" + - PUPPET_VERSION="~>5.0" + - PUPPET_VERSION="~>6.0" rvm: - 2.3.8 From 9844fad19ed7f32275c8ec2f7441c4668dc094c9 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 5 Feb 2019 20:42:02 +0100 Subject: [PATCH 09/10] Mapped tests to PE versions --- .travis.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f014892..8018fa2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,17 @@ cache: script: bundle exec rake full_tests bundler_args: --path vendor/bundle -env: - - PUPPET_VERSION="~>4.0" - - PUPPET_VERSION="~>5.0" - - PUPPET_VERSION="~>6.0" - -rvm: - - 2.3.8 - - 2.4.4 - - 2.5.3 +matrix: + include: + # 2016.x -> 2017.2 + - rvm: 2.1.9 + env: PUPPET_VERSION="~>4.0" + + # 2017.3 -> 2018.1 + - rvm: 2.4.4 + env: PUPPET_VERSION="~>5.0" + + # 2019.0 -> now + - rvm: 2.5.1 + env: PUPPET_VERSION="~>6.0" + \ No newline at end of file From bf2e1b74d876d84e39d5ff4fce3110f2a4c95bc9 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 5 Feb 2019 22:19:49 +0100 Subject: [PATCH 10/10] Removed function type --- README.md | 7 ++++--- lib/onceover/testconfig.rb | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 95dc3e31..86373996 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,8 @@ Why an array of hashes? Well, that is so that we can refer to the same node or n 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. **functions** In this section we can add functions that we want to mock when running spec tests. Each function takes the following arguments: - - **type** *statement or rvalue* - - **returns** *Optional: A value to return* + +- **returns** *Optional: A value to return* **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`. @@ -196,8 +196,9 @@ test_matrix: functions: query_resources: - type: rvalue returns: [] + profile::custom_function: + returns: ["one", "two"] opts: :facts_dirs: diff --git a/lib/onceover/testconfig.rb b/lib/onceover/testconfig.rb index dfa18f87..9e9e9549 100644 --- a/lib/onceover/testconfig.rb +++ b/lib/onceover/testconfig.rb @@ -71,6 +71,11 @@ def initialize(file, opts = {}) @skip_r10k = opts[:skip_r10k] ? true : false @force = opts[:force] || false + # Validate the mock_functions + if @mock_functions && @mock_functions.any? { |name, details| details.has_key? 'type' } + logger.warn "The 'type' key for mocked functions is deprecated and will be ignored, please remove it." + end + # Loop over all of the items in the test matrix and add those as test # objects to the list of tests config['test_matrix'].each do |test_hash|