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 @@ -1,31 +1,29 @@ test_name "should create cron" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" agents.each do |host| step "ensure the user exist via puppet" apply_manifest_on host, create_user 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" run_cron_on(host, :remove, tmpuser) step "remove the user from the system" apply_manifest_on host, delete_user end 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 @@ -1,37 +1,32 @@ test_name "puppet should match existing job" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" 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" run_cron_on(host, :remove, tmpuser) step "remove the user from the system" apply_manifest_on host, delete_user end 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 @@ -1,36 +1,32 @@ test_name "puppet should remove a crontab entry as expected" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" agents.each do |host| step "ensure the user exist via puppet" apply_manifest_on host, create_user step "create the existing job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") 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" run_cron_on(host, :remove, tmpuser) step "remove the user from the system" apply_manifest_on host, delete_user end 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 @@ -1,36 +1,35 @@ test_name "puppet should remove a crontab entry based on command matching" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" cron = '# Puppet Name: crontest\n* * * * * /bin/true\n1 1 1 1 1 /bin/true\n' create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" agents.each do |host| step "ensure the user exist via puppet" apply_manifest_on host, create_user 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" run_cron_on(host,:list,tmpuser) do count = stdout.scan("/bin/true").length fail_test "found /bin/true the wrong number of times (#{count})" unless count == 1 end step "remove the crontab file for that user" run_cron_on(host,:remove,tmpuser) step "remove the user from the system" apply_manifest_on host, delete_user end 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 @@ -1,40 +1,37 @@ test_name "puppet should update existing crontab entry" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" agents.each do |host| step "ensure the user exist via puppet" apply_manifest_on host, create_user step "create the existing job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") 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" run_cron_on(host,:remove,tmpuser) step "remove the user from the system" apply_manifest_on host, delete_user end