X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=test%2Ftest_prune.rb;h=d32fcae00958adc124e4f20885bdfa6bb22e5765;hp=94b819622d69f4cb4aeb6b45f4c03b7a0f21b59f;hb=ef77e919fa61bb5ba7924d49a171dc3a05410a33;hpb=89999ff8292d40bd72ca6cda167b5e4a454b9f0c diff --git a/test/test_prune.rb b/test/test_prune.rb index 94b8196..d32fcae 100644 --- a/test/test_prune.rb +++ b/test/test_prune.rb @@ -14,17 +14,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 +32,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,11 +51,11 @@ 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() + actual = pfapr.list_aliases() expected = [{'address' => 'alice@example.com', 'goto' => 'alice@example.com'}, {'address' => 'bob@example.com', @@ -74,8 +68,8 @@ class TestPrune < MailshearsTest 'goto' => 'carol@example.net'}] assert_equal(expected, actual) - 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 +80,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