diff options
author | Dominic Maraglia <dominic@puppetlabs.com> | 2011-06-27 16:21:39 -0700 |
---|---|---|
committer | Dominic Maraglia <dominic@puppetlabs.com> | 2011-06-27 16:21:39 -0700 |
commit | 243aaa9929aec91b2ede05ccf30553d328afd55c (patch) | |
tree | e25fedceb146cc51f71073dba39563f48a482e6a | |
parent | 567589c26ea029ffca2a9ab000936c7eb4349e22 (diff) | |
download | puppet-243aaa9929aec91b2ede05ccf30553d328afd55c.tar.gz puppet-243aaa9929aec91b2ede05ccf30553d328afd55c.tar.xz puppet-243aaa9929aec91b2ede05ccf30553d328afd55c.zip |
(#7956) Porting cron tests
Ported cron tests were still weak. Coverted tests to use
Ruby asserts for better debugging of subsequent failures.
Add stronger regex's to look for expected output when applying puppet
resource manifests.
5 files changed, 15 insertions, 30 deletions
diff --git a/acceptance/tests/resource/cron/should_create_cron.rb b/acceptance/tests/resource/cron/should_create_cron.rb index 5badac05f..d40228070 100644 --- a/acceptance/tests/resource/cron/should_create_cron.rb +++ b/acceptance/tests/resource/cron/should_create_cron.rb @@ -13,14 +13,12 @@ agents.each do |host| step "apply the resource on the host using puppet resource" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", "command=/bin/true", "ensure=present")) do - fail_test "didn't notice creation of the cron stuff" unless - stdout.include? 'created' + assert_match(/created/, stdout, "Did not create crontab for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host, :list, tmpuser) do - fail_test "didn't find the command as expected" unless - stdout.include? "* * * * * /bin/true" + assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Incorrect crontab for #{tmpuser} on #{host}") end step "remove the crontab file for that user" diff --git a/acceptance/tests/resource/cron/should_match_existing.rb b/acceptance/tests/resource/cron/should_match_existing.rb index b5c5d359d..92e7dc2cc 100755 --- a/acceptance/tests/resource/cron/should_match_existing.rb +++ b/acceptance/tests/resource/cron/should_match_existing.rb @@ -10,23 +10,18 @@ agents.each do |host| step "ensure the user exist via puppet" apply_manifest_on host, create_user - step "create the existing job by hand..." + step "Create the existing cron job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") - step "apply the resource on the host using puppet resource" + step "Apply the resource on the host using puppet resource" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", "command=/bin/true", "ensure=present")) do - # This is a weak/fragile test. The output has changed - # causing this test to fail erronously. Changed to the correct - # output to match, but this code should be re-feactored. - fail_test "didn't see the output we expected..." unless - stdout.include? 'present' + assert_match(/present/, stdout, "Failed creating crontab for #{tmpuser} on #{host}") end - step "verify that crontab -l contains what you expected" + step "Verify that crontab -l contains what you expected" run_cron_on(host, :list, tmpuser) do - fail_test "didn't find the command as expected" unless - stdout.include? "* * * * * /bin/true" + assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Did not find crontab for #{tmpuser} on #{host}") end step "remove the crontab file for that user" diff --git a/acceptance/tests/resource/cron/should_remove_cron.rb b/acceptance/tests/resource/cron/should_remove_cron.rb index 9956d0d71..d6b8822d6 100755 --- a/acceptance/tests/resource/cron/should_remove_cron.rb +++ b/acceptance/tests/resource/cron/should_remove_cron.rb @@ -16,16 +16,12 @@ agents.each do |host| step "apply the resource on the host using puppet resource" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", "command=/bin/true", "ensure=absent")) do - # REVISIT: This is ported from the original test, which seems to me a - # weak test, but I don't want to improve it now. --daniel 2010-12-23 - fail_test "didn't see the output we expected..." unless - stdout.include? 'removed' + assert_match(/crontest\D+ensure:\s+removed/, stdout, "Didn't remove crobtab entry for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host, :list, tmpuser) do - fail_test "didn't found the command we tried to remove" if - stdout.include? "/bin/true" + assert_match(/\/bin\/true/, stdout, "Error: Found entry for #{tmpuser} on #{host}") end step "remove the crontab file for that user" diff --git a/acceptance/tests/resource/cron/should_remove_matching.rb b/acceptance/tests/resource/cron/should_remove_matching.rb index f4de0de0c..59042c7a8 100755 --- a/acceptance/tests/resource/cron/should_remove_matching.rb +++ b/acceptance/tests/resource/cron/should_remove_matching.rb @@ -15,11 +15,10 @@ agents.each do |host| step "create the existing job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") - step "apply the resource change on the host" + step "Remove cron resource" on(host, puppet_resource("cron", "bogus", "user=#{tmpuser}", "command=/bin/true", "ensure=absent")) do - fail_test "didn't see the output we expected..." unless - stdout.include? 'removed' + assert_match(/bogus\D+ensure: removed/, stdout, "Removing cron entry failed for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" diff --git a/acceptance/tests/resource/cron/should_update_existing.rb b/acceptance/tests/resource/cron/should_update_existing.rb index ff179307f..b37952a63 100755 --- a/acceptance/tests/resource/cron/should_update_existing.rb +++ b/acceptance/tests/resource/cron/should_update_existing.rb @@ -15,21 +15,18 @@ agents.each do |host| step "verify that crontab -l contains what you expected" run_cron_on(host,:list,tmpuser) do - fail_test "didn't find the content in the crontab" unless - stdout.include? '* * * * * /bin/true' + assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Didn't find correct crobtab entry for #{tmpuser} on #{host}") end step "apply the resource change on the host" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", - "command=/bin/true", "ensure=present", "hour='0-6'")) do - fail_test "didn't update the time as expected" unless - stdout.include? "hour => ['0-6']" + "command=/bin/true", "ensure=present", "hour='0-6'")) do + assert_match(/hour\s+=>\s+\['0-6'\]/, stdout, "Modifying cron entry failed for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host,:list,tmpuser) do - fail_test "didn't find the content in the crontab" unless - stdout.include? '* 0-6 * * * /bin/true' + assert_match(/\* 0-6 \* \* \* \/bin\/true/, stdout, "Didn't find correctly modified time entry in crobtab entry for #{tmpuser} on #{host}") end step "remove the crontab file for that user" |