]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Add an idempotence test for pruning.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 4 Nov 2015 16:40:23 +0000 (11:40 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 4 Nov 2015 16:40:23 +0000 (11:40 -0500)
doc/TODO
test/test_prune.rb

index 5b007a9b3d89a37d1314fcc77cc452a248116bf2..92a90b4bb1f1021e10b3408cac6774304a0229b3 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -15,8 +15,6 @@
 
 * Write a man page.
 
 
 * Write a man page.
 
-* Tests: Add an idempotence test for prune.
-
 * Tests: Check that child tables contain what they're supposed to, too.
 
 * Update the README.
 * Tests: Check that child tables contain what they're supposed to, too.
 
 * Update the README.
index 94b819622d69f4cb4aeb6b45f4c03b7a0f21b59f..a0e69417e0f633cf1eeba599ff4d31fd39ec5a36 100644 (file)
@@ -14,17 +14,11 @@ require 'prune/prune_runner'
 
 class TestPrune < MailshearsTest
 
 
 class TestPrune < MailshearsTest
 
-  def test_single_prune
+  def check_assertions(actual)
     cfg = configuration()
 
     cfg = configuration()
 
-    output_buffer = StringIO.new()
-
-    $stdout = output_buffer
-    PrunePlugin.run(cfg)
-    $stdout = STDOUT
-
-    actual = output_buffer.string()
-
+    # Both of our tests have the same expected output / results, so
+    # check them both using the same function.
     expected =
       "AgendavPrune - Removed user booger@example.com.\n" +
       "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
     expected =
       "AgendavPrune - Removed user booger@example.com.\n" +
       "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
@@ -86,4 +80,39 @@ class TestPrune < MailshearsTest
     assert(!maildir_exists('example.com/jeremy'))
   end
 
     assert(!maildir_exists('example.com/jeremy'))
   end
 
+
+  def test_single_prune()
+    # Run prune once and see what happens.
+    cfg = configuration()
+
+    output_buffer = StringIO.new()
+
+    $stdout = output_buffer
+    PrunePlugin.run(cfg)
+    $stdout = STDOUT
+
+    actual = output_buffer.string()
+
+    check_assertions(actual)
+  end
+
+
+  def test_double_prune
+    # Run prune twice. This should have the exact same output as
+    # running it once, since the second time around, there's nothing
+    # to prune.
+    cfg = configuration()
+
+    output_buffer = StringIO.new()
+
+    $stdout = output_buffer
+    PrunePlugin.run(cfg)
+    PrunePlugin.run(cfg)
+    $stdout = STDOUT
+
+    actual = output_buffer.string()
+
+    check_assertions(actual)
+  end
+
 end
 end