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.

Signed-off-by: Dominic Maraglia <[email protected]>
---
 .../tests/resource/cron/should_create_cron.rb      |    6 ++----
 .../tests/resource/cron/should_match_existing.rb   |   15 +++++----------
 .../tests/resource/cron/should_remove_cron.rb      |    8 ++------
 .../tests/resource/cron/should_remove_matching.rb  |    5 ++---
 .../tests/resource/cron/should_update_existing.rb  |   11 ++++-------
 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 5badac0..d402280 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 b5c5d35..92e7dc2 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 9956d0d..d6b8822 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 f4de0de..59042c7 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 ff17930..b37952a 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"
-- 
1.7.3.5

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to