diff options
author | Jorie Tappa <jorie@jorietappa.com> | 2018-08-23 13:01:25 -0700 |
---|---|---|
committer | Jorie Tappa <jorie@jorietappa.com> | 2018-08-23 13:01:25 -0700 |
commit | b94412afd6be6155b7384c37378d985826528670 (patch) | |
tree | f041e9862affe7e5b2a9982316305c34d1cb65e0 | |
parent | 3b48bc4a5a9d3703fbb01d3d6e70cbf2240f0e8b (diff) | |
download | puppet-cron_core-b94412afd6be6155b7384c37378d985826528670.tar.gz puppet-cron_core-b94412afd6be6155b7384c37378d985826528670.tar.bz2 |
Fix acceptance tests
11 files changed, 66 insertions, 46 deletions
diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..2cd2823 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,19 @@ +--- +HOSTS: + centos7-64-1: + pe_dir: + pe_ver: + pe_upgrade_dir: + pe_upgrade_ver: + hypervisor: vmpooler + platform: centos-7-x86_64 + packaging_platform: el-7-x86_64 + template: centos-7-x86_64 + roles: + - agent + - default +CONFIG: + type: agent + nfs_server: none + consoleport: 443 + pooling_api: http://vmpooler.delivery.puppetlabs.net/
\ No newline at end of file diff --git a/spec/acceptance/tests/resource/cron/should_allow_changing_parameters_spec.rb b/spec/acceptance/tests/resource/cron/should_allow_changing_parameters_spec.rb index 2ff0dc4..2df0ea2 100644 --- a/spec/acceptance/tests/resource/cron/should_allow_changing_parameters_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_allow_changing_parameters_spec.rb @@ -1,19 +1,17 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when changing parameters' do +RSpec.context 'when changing parameters' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' - setup(agent) + setup agent end end after(:each) do compatible_agents.each do |agent| step 'Cron: cleanup' - clean(agent) + clean agent end end @@ -21,50 +19,50 @@ Rspec.context 'when changing parameters' do it "manages cron entries on #{agent}" do step 'Cron: basic - verify that it can be created' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/false", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do - expect(result.stdout).to match(%r{ensure: created}) + expect(@result.stdout).to match(%r{ensure: created}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{.bin.false}) + expect(@result.stdout).to match(%r{.bin.false}) end step 'Cron: allow changing command' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do - expect(result.stdout).to match(%r{command changed '.bin.false'.* to '.bin.true'}) + expect(@result.stdout).to match(%r{command changed '.bin.false'.* to '.bin.true'}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{1 . . . . .bin.true}) + expect(@result.stdout).to match(%r{1 . . . . .bin.true}) end step 'Cron: allow changing time' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "1", minute => [1], ensure => present,}') do - expect(result.stdout).to match(%r{hour: defined 'hour' as \['1'\]}) + expect(@result.stdout).to match(%r{hour: defined 'hour' as \['1'\]}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{1 1 . . . .bin.true}) + expect(@result.stdout).to match(%r{1 1 . . . .bin.true}) end step 'Cron: allow changing time(array)' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => ["1","2"], minute => [1], ensure => present,}') do - expect(result.stdout).to match(%r{hour: hour changed \['1'\].* to \['1', '2'\]}) + expect(@result.stdout).to match(%r{hour: hour changed \['1'\].* to \['1', '2'\]}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{1 1,2 . . . .bin.true}) + expect(@result.stdout).to match(%r{1 1,2 . . . .bin.true}) end step 'Cron: allow changing time(array modification)' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => ["3","2"], minute => [1], ensure => present,}') do - expect(result.stdout).to match(%r{hour: hour changed \['1', '2'\].* to \['3', '2'\]}) + expect(@result.stdout).to match(%r{hour: hour changed \['1', '2'\].* to \['3', '2'\]}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{1 3,2 . . . .bin.true}) + expect(@result.stdout).to match(%r{1 3,2 . . . .bin.true}) end step 'Cron: allow changing time(array modification to *)' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => "*", ensure => present,}') do - expect(result.stdout).to match(%r{minute: undefined 'minute' from \['1'\]}) - expect(result.stdout).to match(%r{hour: undefined 'hour' from \['3', '2'\]}) + expect(@result.stdout).to match(%r{minute: undefined 'minute' from \['1'\]}) + expect(@result.stdout).to match(%r{hour: undefined 'hour' from \['3', '2'\]}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{\* \* . . . .bin.true}) + expect(@result.stdout).to match(%r{\* \* . . . .bin.true}) end end end diff --git a/spec/acceptance/tests/resource/cron/should_be_idempotent_spec.rb b/spec/acceptance/tests/resource/cron/should_be_idempotent_spec.rb index 7d4d386..4bf515e 100644 --- a/spec/acceptance/tests/resource/cron/should_be_idempotent_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_be_idempotent_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when checking idempotency' do +RSpec.context 'when checking idempotency' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' @@ -21,15 +19,15 @@ Rspec.context 'when checking idempotency' do it "ensures idempotency on #{agent}" do step 'Cron: basic - verify that it can be created' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do - expect(result.stdout).to match(%r{ensure: created}) + expect(@result.stdout).to match(%r{ensure: created}) end run_cron_on(agent, :list, 'tstuser') do - expect(result.stdout).to match(%r{. . . . . .bin.true}) + expect(@result.stdout).to match(%r{. . . . . .bin.true}) end step 'Cron: basic - should not create again' apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do - expect(result.stdout).not_to match(%r{ensure: created}) + expect(@result.stdout).not_to match(%r{ensure: created}) end end end diff --git a/spec/acceptance/tests/resource/cron/should_create_cron_spec.rb b/spec/acceptance/tests/resource/cron/should_create_cron_spec.rb index b1623a4..05ae5e5 100644 --- a/spec/acceptance/tests/resource/cron/should_create_cron_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_create_cron_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when creating cron' do +RSpec.context 'when creating cron' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' @@ -18,7 +16,7 @@ Rspec.context 'when creating cron' do end compatible_agents.each do |host| - it 'creates a cron' do + it 'creates a new cron job' do step 'apply the resource on the host using puppet resource' on(host, puppet_resource('cron', 'crontest', 'user=tstuser', 'command=/bin/true', 'ensure=present')) do expect(stdout).to match(%r{created}) diff --git a/spec/acceptance/tests/resource/cron/should_match_existing_spec.rb b/spec/acceptance/tests/resource/cron/should_match_existing_spec.rb index 8097714..ce25be7 100644 --- a/spec/acceptance/tests/resource/cron/should_match_existing_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_match_existing_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when matching cron' do +RSpec.context 'when matching cron' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' diff --git a/spec/acceptance/tests/resource/cron/should_remove_cron_spec.rb b/spec/acceptance/tests/resource/cron/should_remove_cron_spec.rb index 89190a5..d23cded 100644 --- a/spec/acceptance/tests/resource/cron/should_remove_cron_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_remove_cron_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when removing crontab' do +RSpec.context 'when removing crontab' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' @@ -28,9 +26,9 @@ Rspec.context 'when removing crontab' do expect(stdout).to match(%r{crontest\D+ensure:\s+removed}) end - step 'verify that crontab -l contains what you expected' + step ' contains what you expected' run_cron_on(host, :list, 'tstuser') do - expect(stderr).to match(%r{/bin/true}) + expect(stderr).not_to match(%r{/bin/true}) end end end diff --git a/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace_spec.rb b/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace_spec.rb index c840166..da04daa 100644 --- a/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when stripping whitespace from cron jobs' do +RSpec.context 'when stripping whitespace from cron jobs' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' diff --git a/spec/acceptance/tests/resource/cron/should_remove_matching_spec.rb b/spec/acceptance/tests/resource/cron/should_remove_matching_spec.rb index 5a814ae..652d8c5 100644 --- a/spec/acceptance/tests/resource/cron/should_remove_matching_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_remove_matching_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when removing crontabs' do +RSpec.context 'when removing crontabs' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' diff --git a/spec/acceptance/tests/resource/cron/should_update_existing_spec.rb b/spec/acceptance/tests/resource/cron/should_update_existing_spec.rb index 9f0731b..3b226e7 100644 --- a/spec/acceptance/tests/resource/cron/should_update_existing_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_update_existing_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper_acceptance' -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CronUtils -Rspec.context 'when updating cron jobs' do +RSpec.context 'when updating cron jobs' do before(:each) do compatible_agents.each do |agent| step 'ensure the user exists via puppet' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69d11d..5e721b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,3 @@ - require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e0a23cb..b56c203 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -2,6 +2,8 @@ require 'beaker-rspec' require 'beaker/module_install_helper' require 'beaker/puppet_install_helper' +$LOAD_PATH << File.join(__dir__, 'acceptance/lib') + def beaker_opts { debug: true, trace: true, expect_failures: true, acceptable_exit_codes: (0...256) } # { expect_failures: true, acceptable_exit_codes: (0...256) } @@ -11,6 +13,22 @@ def compatible_agents agents.reject { |agent| agent['platform'].include?('windows') || agent['platform'].include?('eos-') || agent['platform'].include?('fedora-28') } end +def clean(agent, o={}) + o = {:user => 'tstuser'}.merge(o) + run_cron_on(agent, :remove, o[:user]) + apply_manifest_on(agent, %[user { '%s': ensure => absent, managehome => false }] % o[:user]) + end + +def setup(agent, o={}) + o = {:user => 'tstuser'}.merge(o) + apply_manifest_on(agent, %[user { '%s': ensure => present, managehome => false }] % o[:user]) + apply_manifest_on(agent, %[case $operatingsystem { + centos, redhat: {$cron = 'cronie'} + solaris: { $cron = 'core-os' } + default: {$cron ='cron'} } + package {'cron': name=> $cron, ensure=>present, }]) +end + RSpec.configure do |c| c.before :suite do unless ENV['BEAKER_provision'] == 'no' |