]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Add a test case for prune.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 4 Nov 2015 05:18:45 +0000 (00:18 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 4 Nov 2015 05:18:45 +0000 (00:18 -0500)
test/test_prune.rb [new file with mode: 0644]

diff --git a/test/test_prune.rb b/test/test_prune.rb
new file mode 100644 (file)
index 0000000..94b8196
--- /dev/null
@@ -0,0 +1,89 @@
+# WARNING: Test output is dependent on the order these classes include
+# certain modules; i.e. on the 'require' order.
+require 'common/domain'
+require 'common/user'
+require 'mailshears_test'
+require 'minitest/autorun'
+require 'prune/plugins/agendav'
+require 'prune/plugins/davical'
+require 'prune/plugins/dovecot'
+require 'prune/plugins/postfixadmin'
+require 'prune/plugins/roundcube'
+require 'prune/prune_runner'
+
+
+class TestPrune < MailshearsTest
+
+  def test_single_prune
+    cfg = configuration()
+
+    output_buffer = StringIO.new()
+
+    $stdout = output_buffer
+    PrunePlugin.run(cfg)
+    $stdout = STDOUT
+
+    actual = output_buffer.string()
+
+    expected =
+      "AgendavPrune - Removed user booger@example.com.\n" +
+      "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
+      "DovecotPrune - Removed user booger@example.com " +
+        "(#{cfg.dovecot_mail_root()}/example.com/booger).\n" +
+      "DovecotPrune - Removed user jeremy@example.com " +
+        "(#{cfg.dovecot_mail_root()}/example.com/jeremy).\n" +
+      "RoundcubePrune - Removed user booger@example.com (User ID: 2).\n"
+
+    assert_equal(expected, actual)
+
+    # Now make sure the database has what we expect.
+
+    arm = AgendavPrune.new(cfg)
+    actual = arm.list_users()
+    expected = [User.new('adam@example.net')]
+    assert_equal(expected, actual)
+
+    drm = DavicalPrune.new(cfg)
+    actual = drm.list_users()
+    expected = [User.new('alice@example.com')]
+    assert_equal(expected, actual)
+
+    pfarm = PostfixadminPrune.new(cfg)
+    actual = pfarm.list_users()
+    expected = [User.new('alice@example.com'),
+                User.new('bob@example.com'),
+                User.new('adam@example.net'),
+                User.new('beth@example.net'),
+                User.new('carol@example.net')]
+    assert_equal(expected, actual)
+
+    actual = pfarm.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'},
+                {'address' => 'beth@example.net',
+                    'goto' => 'beth@example.net'},
+                {'address' => 'carol@example.net',
+                    'goto' => 'carol@example.net'}]
+    assert_equal(expected, actual)
+
+    rrm = RoundcubePrune.new(cfg)
+    actual = rrm.list_users()
+    expected = [User.new('alice@example.com'), User.new('adam@example.net')]
+    assert_equal(expected, actual)
+
+    # Booger and Jeremy should get pruned.
+    assert(maildir_exists('example.com/alice'))
+    assert(maildir_exists('example.net/adam'))
+    assert(!maildir_exists('example.com/booger'))
+    assert(!maildir_exists('example.com/jeremy'))
+  end
+
+end