]>
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 apr
= AgendavPrune
.new(cfg
)
36 actual
= apr
.list_users()
37 expected
= [User
.new('adam@example.net')]
38 assert_equal(expected
, actual
)
40 dpr
= DavicalPrune
.new(cfg
)
41 actual
= dpr
.list_users()
42 expected
= [User
.new('alice@example.com')]
43 assert_equal(expected
, actual
)
45 pfapr
= PostfixadminPrune
.new(cfg
)
46 actual
= pfapr
.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
= pfapr
.list_domains()
55 expected
= [Domain
.new('example.com'), Domain
.new('example.net')]
56 assert_equal(expected
, actual
)
58 actual
= pfapr
.list_aliases()
59 expected
= [{'address' => 'adam@example.net',
60 'goto' => 'adam@example.net'},
61 {'address' => 'alice@example.com',
62 'goto' => 'alice@example.com,' +
66 {'address' => 'beth@example.net',
67 'goto' => 'beth@example.net'},
68 {'address' => 'bob@example.com',
69 'goto' => 'bob@example.com'},
70 {'address' => 'carol@example.net',
71 'goto' => 'carol@example.net'}]
72 expected
.each
{ |e
| assert(actual
.include?(e
)) } # can't sort dicts
73 actual
.each
{ |a
| assert(expected
.include?(a
)) } # can't sort dicts
75 rpr
= RoundcubePrune
.new(cfg
)
76 actual
= rpr
.list_users()
77 expected
= [User
.new('alice@example.com'), User
.new('adam@example.net')]
78 assert_equal(expected
, actual
)
80 # Booger and Jeremy should get pruned.
81 assert(maildir_exists('example.com/alice'))
82 assert(maildir_exists('example.net/adam'))
83 assert(!
maildir_exists('example.com/booger'))
84 assert(!
maildir_exists('example.com/jeremy'))
88 def test_single_prune()
89 # Run prune once and see what happens.
92 output_buffer
= StringIO
.new()
94 $stdout = output_buffer
98 actual
= output_buffer
.string()
100 check_assertions(actual
)
104 def test_double_prune
105 # Run prune twice. This should have the exact same output as
106 # running it once, since the second time around, there's nothing
108 cfg
= configuration()
110 output_buffer
= StringIO
.new()
112 $stdout = output_buffer
117 actual
= output_buffer
.string()
119 check_assertions(actual
)