]>
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 'prune/plugins/davical'
7 require 'prune/plugins/dovecot'
8 require 'prune/plugins/postfixadmin'
9 require 'prune/plugins/roundcube'
10 require 'prune/prune_runner'
13 class TestPrune
< MailshearsTest
15 def check_assertions(actual
)
18 # Both of our tests have the same expected output / results, so
19 # check them both using the same function.
21 "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
22 "DovecotPrune - Removed user booger@example.com " +
23 "(#{cfg.dovecot_mail_root()}/example.com/booger).\n" +
24 "DovecotPrune - Removed user jeremy@example.com " +
25 "(#{cfg.dovecot_mail_root()}/example.com/jeremy).\n" +
26 "RoundcubePrune - Removed user booger@example.com (User ID: 2).\n"
28 assert_equal(expected
, actual
)
30 # Now make sure the database has what we expect.
32 dpr
= DavicalPrune
.new(cfg
)
33 actual
= dpr
.list_users()
34 expected
= [User
.new('alice@example.com')]
35 assert_equal(expected
, actual
)
37 pfapr
= PostfixadminPrune
.new(cfg
)
38 actual
= pfapr
.list_users()
39 expected
= [User
.new('alice@example.com'),
40 User
.new('bob@example.com'),
41 User
.new('adam@example.net'),
42 User
.new('beth@example.net'),
43 User
.new('carol@example.net')]
44 assert_equal(expected
, actual
)
46 actual
= pfapr
.list_domains()
47 expected
= [Domain
.new('example.com'), Domain
.new('example.net')]
48 assert_equal(expected
, actual
)
50 actual
= pfapr
.list_aliases()
51 expected
= [{'address' => 'adam@example.net',
52 'goto' => 'adam@example.net'},
53 {'address' => 'alice@example.com',
54 'goto' => 'alice@example.com,' +
58 {'address' => 'beth@example.net',
59 'goto' => 'beth@example.net'},
60 {'address' => 'bob@example.com',
61 'goto' => 'bob@example.com'},
62 {'address' => 'carol@example.net',
63 'goto' => 'carol@example.net'}]
64 expected
.each
{ |e
| assert(actual
.include?(e
)) } # can't sort dicts
65 actual
.each
{ |a
| assert(expected
.include?(a
)) } # can't sort dicts
67 rpr
= RoundcubePrune
.new(cfg
)
68 actual
= rpr
.list_users()
69 expected
= [User
.new('alice@example.com'), User
.new('adam@example.net')]
70 assert_equal(expected
, actual
)
72 # Booger and Jeremy should get pruned.
73 assert(maildir_exists('example.com/alice'))
74 assert(maildir_exists('example.net/adam'))
75 assert(!
maildir_exists('example.com/booger'))
76 assert(!
maildir_exists('example.com/jeremy'))
80 def test_single_prune()
81 # Run prune once and see what happens.
84 output_buffer
= StringIO
.new()
86 $stdout = output_buffer
90 actual
= output_buffer
.string()
92 check_assertions(actual
)
97 # Run prune twice. This should have the exact same output as
98 # running it once, since the second time around, there's nothing
100 cfg
= configuration()
102 output_buffer
= StringIO
.new()
104 $stdout = output_buffer
109 actual
= output_buffer
.string()
111 check_assertions(actual
)