]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - test/test_prune.rb
Fix the new AgenDAV fixtures SQL.
[mailshears.git] / test / test_prune.rb
index 94b819622d69f4cb4aeb6b45f4c03b7a0f21b59f..059de528359c1386dfa62c095bfd16e3473f39c7 100644 (file)
@@ -3,7 +3,6 @@
 require 'common/domain'
 require 'common/user'
 require 'mailshears_test'
-require 'minitest/autorun'
 require 'prune/plugins/agendav'
 require 'prune/plugins/davical'
 require 'prune/plugins/dovecot'
@@ -14,17 +13,11 @@ require 'prune/prune_runner'
 
 class TestPrune < MailshearsTest
 
-  def test_single_prune
+  def check_assertions(actual)
     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" +
@@ -38,18 +31,18 @@ class TestPrune < MailshearsTest
 
     # Now make sure the database has what we expect.
 
-    arm = AgendavPrune.new(cfg)
-    actual = arm.list_users()
+    apr = AgendavPrune.new(cfg)
+    actual = apr.list_users()
     expected = [User.new('adam@example.net')]
     assert_equal(expected, actual)
 
-    drm = DavicalPrune.new(cfg)
-    actual = drm.list_users()
+    dpr = DavicalPrune.new(cfg)
+    actual = dpr.list_users()
     expected = [User.new('alice@example.com')]
     assert_equal(expected, actual)
 
-    pfarm = PostfixadminPrune.new(cfg)
-    actual = pfarm.list_users()
+    pfapr = PostfixadminPrune.new(cfg)
+    actual = pfapr.list_users()
     expected = [User.new('alice@example.com'),
                 User.new('bob@example.com'),
                 User.new('adam@example.net'),
@@ -57,25 +50,29 @@ class TestPrune < MailshearsTest
                 User.new('carol@example.net')]
     assert_equal(expected, actual)
 
-    actual = pfarm.list_domains()
+    actual = pfapr.list_domains()
     expected = [Domain.new('example.com'), Domain.new('example.net')]
     assert_equal(expected, actual)
 
-    actual = pfarm.list_aliases()
-    expected = [{'address' => 'alice@example.com',
-                    'goto' => 'alice@example.com'},
-                {'address' => 'bob@example.com',
-                    'goto' => 'bob@example.com'},
-                {'address' => 'adam@example.net',
-                    'goto' => 'adam@example.net'},
+    actual = pfapr.list_aliases()
+    expected = [{'address' => 'adam@example.net',
+                 'goto' => 'adam@example.net'},
+                {'address' => 'alice@example.com',
+                 'goto' => 'alice@example.com,' +
+                           'adam@example.net,' +
+                           'bob@example.com,' +
+                           'carol@example.net'},
                 {'address' => 'beth@example.net',
-                    'goto' => 'beth@example.net'},
+                 'goto' => 'beth@example.net'},
+                {'address' => 'bob@example.com',
+                 'goto' => 'bob@example.com'},
                 {'address' => 'carol@example.net',
-                    'goto' => 'carol@example.net'}]
-    assert_equal(expected, actual)
+                 'goto' => 'carol@example.net'}]
+    expected.each { |e| assert(actual.include?(e)) } # can't sort dicts
+    actual.each { |a| assert(expected.include?(a)) } # can't sort dicts
 
-    rrm = RoundcubePrune.new(cfg)
-    actual = rrm.list_users()
+    rpr = RoundcubePrune.new(cfg)
+    actual = rpr.list_users()
     expected = [User.new('alice@example.com'), User.new('adam@example.net')]
     assert_equal(expected, actual)
 
@@ -86,4 +83,39 @@ class TestPrune < MailshearsTest
     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