]>
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/agendav'
7 require 'prune/plugins/davical'
8 require 'prune/plugins/dovecot'
9 require 'prune/plugins/postfixadmin'
10 require 'prune/plugins/roundcube'
11 require 'prune/prune_runner'
14 class TestPrune
< MailshearsTest
16 def check_assertions(actual
)
19 # Both of our tests have the same expected output / results, so
20 # check them both using the same function.
22 "AgendavPrune - Removed user booger@example.com.\n" +
23 "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
24 "DovecotPrune - Removed user booger@example.com " +
25 "(#{cfg.dovecot_mail_root()}/example.com/booger).\n" +
26 "DovecotPrune - Removed user jeremy@example.com " +
27 "(#{cfg.dovecot_mail_root()}/example.com/jeremy).\n" +
28 "RoundcubePrune - Removed user booger@example.com (User ID: 2).\n"
30 assert_equal(expected
, actual
)
32 # Now make sure the database has what we expect.
34 apr
= AgendavPrune
.new(cfg
)
35 actual
= apr
.list_users()
36 expected
= [User
.new('adam@example.net')]
37 assert_equal(expected
, actual
)
39 dpr
= DavicalPrune
.new(cfg
)
40 actual
= dpr
.list_users()
41 expected
= [User
.new('alice@example.com')]
42 assert_equal(expected
, actual
)
44 pfapr
= PostfixadminPrune
.new(cfg
)
45 actual
= pfapr
.list_users()
46 expected
= [User
.new('alice@example.com'),
47 User
.new('bob@example.com'),
48 User
.new('adam@example.net'),
49 User
.new('beth@example.net'),
50 User
.new('carol@example.net')]
51 assert_equal(expected
, actual
)
53 actual
= pfapr
.list_domains()
54 expected
= [Domain
.new('example.com'), Domain
.new('example.net')]
55 assert_equal(expected
, actual
)
57 actual
= pfapr
.list_aliases()
58 expected
= [{'address' => 'adam@example.net',
59 'goto' => 'adam@example.net'},
60 {'address' => 'alice@example.com',
61 'goto' => 'alice@example.com,' +
65 {'address' => 'beth@example.net',
66 'goto' => 'beth@example.net'},
67 {'address' => 'bob@example.com',
68 'goto' => 'bob@example.com'},
69 {'address' => 'carol@example.net',
70 'goto' => 'carol@example.net'}]
71 expected
.each
{ |e
| assert(actual
.include?(e
)) } # can't sort dicts
72 actual
.each
{ |a
| assert(expected
.include?(a
)) } # can't sort dicts
74 rpr
= RoundcubePrune
.new(cfg
)
75 actual
= rpr
.list_users()
76 expected
= [User
.new('alice@example.com'), User
.new('adam@example.net')]
77 assert_equal(expected
, actual
)
79 # Booger and Jeremy should get pruned.
80 assert(maildir_exists('example.com/alice'))
81 assert(maildir_exists('example.net/adam'))
82 assert(!
maildir_exists('example.com/booger'))
83 assert(!
maildir_exists('example.com/jeremy'))
87 def test_single_prune()
88 # Run prune once and see what happens.
91 output_buffer
= StringIO
.new()
93 $stdout = output_buffer
97 actual
= output_buffer
.string()
99 check_assertions(actual
)
103 def test_double_prune
104 # Run prune twice. This should have the exact same output as
105 # running it once, since the second time around, there's nothing
107 cfg
= configuration()
109 output_buffer
= StringIO
.new()
111 $stdout = output_buffer
116 actual
= output_buffer
.string()
118 check_assertions(actual
)