]>
gitweb.michael.orlitzky.com - mailshears.git/blob - test/test_prune.rb
1 # WARNING: Test output is dependent on the order these classes include
2 # certain modules; i.e. on the 'require' order.
3 require 'common/domain'
5 require 'mailshears_test'
6 require 'minitest/autorun'
7 require 'prune/plugins/agendav'
8 require 'prune/plugins/davical'
9 require 'prune/plugins/dovecot'
10 require 'prune/plugins/postfixadmin'
11 require 'prune/plugins/roundcube'
12 require 'prune/prune_runner'
15 class TestPrune
< MailshearsTest
17 def check_assertions(actual
)
20 # Both of our tests have the same expected output / results, so
21 # check them both using the same function.
23 "AgendavPrune - Removed user booger@example.com.\n" +
24 "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
25 "DovecotPrune - Removed user booger@example.com " +
26 "(#{cfg.dovecot_mail_root()}/example.com/booger).\n" +
27 "DovecotPrune - Removed user jeremy@example.com " +
28 "(#{cfg.dovecot_mail_root()}/example.com/jeremy).\n" +
29 "RoundcubePrune - Removed user booger@example.com (User ID: 2).\n"
31 assert_equal(expected
, actual
)
33 # Now make sure the database has what we expect.
35 arm
= AgendavPrune
.new(cfg
)
36 actual
= arm
.list_users()
37 expected
= [User
.new('adam@example.net')]
38 assert_equal(expected
, actual
)
40 drm
= DavicalPrune
.new(cfg
)
41 actual
= drm
.list_users()
42 expected
= [User
.new('alice@example.com')]
43 assert_equal(expected
, actual
)
45 pfarm
= PostfixadminPrune
.new(cfg
)
46 actual
= pfarm
.list_users()
47 expected
= [User
.new('alice@example.com'),
48 User
.new('bob@example.com'),
49 User
.new('adam@example.net'),
50 User
.new('beth@example.net'),
51 User
.new('carol@example.net')]
52 assert_equal(expected
, actual
)
54 actual
= pfarm
.list_domains()
55 expected
= [Domain
.new('example.com'), Domain
.new('example.net')]
56 assert_equal(expected
, actual
)
58 actual
= pfarm
.list_aliases()
59 expected
= [{'address' => 'alice@example.com',
60 'goto' => 'alice@example.com'},
61 {'address' => 'bob@example.com',
62 'goto' => 'bob@example.com'},
63 {'address' => 'adam@example.net',
64 'goto' => 'adam@example.net'},
65 {'address' => 'beth@example.net',
66 'goto' => 'beth@example.net'},
67 {'address' => 'carol@example.net',
68 'goto' => 'carol@example.net'}]
69 assert_equal(expected
, actual
)
71 rrm
= RoundcubePrune
.new(cfg
)
72 actual
= rrm
.list_users()
73 expected
= [User
.new('alice@example.com'), User
.new('adam@example.net')]
74 assert_equal(expected
, actual
)
76 # Booger and Jeremy should get pruned.
77 assert(maildir_exists('example.com/alice'))
78 assert(maildir_exists('example.net/adam'))
79 assert(!
maildir_exists('example.com/booger'))
80 assert(!
maildir_exists('example.com/jeremy'))
84 def test_single_prune()
85 # Run prune once and see what happens.
88 output_buffer
= StringIO
.new()
90 $stdout = output_buffer
94 actual
= output_buffer
.string()
96 check_assertions(actual
)
100 def test_double_prune
101 # Run prune twice. This should have the exact same output as
102 # running it once, since the second time around, there's nothing
104 cfg
= configuration()
106 output_buffer
= StringIO
.new()
108 $stdout = output_buffer
113 actual
= output_buffer
.string()
115 check_assertions(actual
)