From a08d680054b7ba482520abdabb8a9f94015db748 Mon Sep 17 00:00:00 2001 From: Sofer Athlan-Guyot Date: Tue, 5 Jul 2016 14:17:35 +0200 Subject: [PATCH] Adjust smoke test to search in examples directory. The latest puppet recommendation are for examples of working manifest to be put in the examples directory. This patch ensure that we first search this one before moving on the tests directory, for backward compatibility. Change-Id: I2699eaa3a10589c9a0c680bb1de489994fe01b67 --- .../shared_examples_acceptance.rb | 6 ++--- .../support/helpers/smoke_test.rb | 27 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/puppet-openstack_spec_helper/shared_examples_acceptance.rb b/lib/puppet-openstack_spec_helper/shared_examples_acceptance.rb index b143e61..7ea11c3 100644 --- a/lib/puppet-openstack_spec_helper/shared_examples_acceptance.rb +++ b/lib/puppet-openstack_spec_helper/shared_examples_acceptance.rb @@ -8,9 +8,9 @@ shared_examples_for 'puppet_apply_success' do |manifest| end end -# Test a normal puppet run with idempotency using files in the tests -# directory (smoke testing) -shared_examples_for 'puppet_apply_success_from_tests' do |test_file| +# Test a normal puppet run with idempotency using files in the +# examples/tests directory (smoke testing) +shared_examples_for 'puppet_apply_success_from_example' do |test_file| it 'should apply the manifest without error' do apply_manifest(smoke_test_named(test_file), :catch_failures => true) end diff --git a/lib/puppet-openstack_spec_helper/support/helpers/smoke_test.rb b/lib/puppet-openstack_spec_helper/support/helpers/smoke_test.rb index 702b489..0d9f442 100644 --- a/lib/puppet-openstack_spec_helper/support/helpers/smoke_test.rb +++ b/lib/puppet-openstack_spec_helper/support/helpers/smoke_test.rb @@ -1,19 +1,30 @@ module PuppetOpenstackSpecHelpers module SmokeTest def smoke_test_named(file) - smoke_dir = File.join(project_root_directory, 'tests') - smoke_manifest_file = File.join(smoke_dir, - file.sub(/\.pp$/, '') + '.pp') - - unless File.exists?(smoke_manifest_file) - raise ArgumentError, - "Cannot find smoke manifest file '#{smoke_manifest_file}'" - end + smoke_manifest_file = example_file(file) File.read(smoke_manifest_file) end def project_root_directory RSpec::Core::RubyProject.root end + + private + def example_file(file) + smoke_manifest_file = '' + found = true + ['examples', 'tests'].each do |ex_dir| + smoke_dir = File.join(project_root_directory, ex_dir) + smoke_manifest_file = File.join(smoke_dir, + file.sub(/\.pp$/, '') + '.pp') + break if File.exists?(smoke_manifest_file) + found = false + end + unless found + raise ArgumentError, + "Cannot find smoke manifest file '#{file}' in 'tests' or 'examples' directory" + end + smoke_manifest_file + end end end