94b819622d69f4cb4aeb6b45f4c03b7a0f21b59f
[mailshears.git] / 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'
4 require 'common/user'
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'
13
14
15 class TestPrune < MailshearsTest
16
17 def test_single_prune
18 cfg = configuration()
19
20 output_buffer = StringIO.new()
21
22 $stdout = output_buffer
23 PrunePlugin.run(cfg)
24 $stdout = STDOUT
25
26 actual = output_buffer.string()
27
28 expected =
29 "AgendavPrune - Removed user booger@example.com.\n" +
30 "DavicalPrune - Removed user booger@example.com (Principal ID: 2).\n" +
31 "DovecotPrune - Removed user booger@example.com " +
32 "(#{cfg.dovecot_mail_root()}/example.com/booger).\n" +
33 "DovecotPrune - Removed user jeremy@example.com " +
34 "(#{cfg.dovecot_mail_root()}/example.com/jeremy).\n" +
35 "RoundcubePrune - Removed user booger@example.com (User ID: 2).\n"
36
37 assert_equal(expected, actual)
38
39 # Now make sure the database has what we expect.
40
41 arm = AgendavPrune.new(cfg)
42 actual = arm.list_users()
43 expected = [User.new('adam@example.net')]
44 assert_equal(expected, actual)
45
46 drm = DavicalPrune.new(cfg)
47 actual = drm.list_users()
48 expected = [User.new('alice@example.com')]
49 assert_equal(expected, actual)
50
51 pfarm = PostfixadminPrune.new(cfg)
52 actual = pfarm.list_users()
53 expected = [User.new('alice@example.com'),
54 User.new('bob@example.com'),
55 User.new('adam@example.net'),
56 User.new('beth@example.net'),
57 User.new('carol@example.net')]
58 assert_equal(expected, actual)
59
60 actual = pfarm.list_domains()
61 expected = [Domain.new('example.com'), Domain.new('example.net')]
62 assert_equal(expected, actual)
63
64 actual = pfarm.list_aliases()
65 expected = [{'address' => 'alice@example.com',
66 'goto' => 'alice@example.com'},
67 {'address' => 'bob@example.com',
68 'goto' => 'bob@example.com'},
69 {'address' => 'adam@example.net',
70 'goto' => 'adam@example.net'},
71 {'address' => 'beth@example.net',
72 'goto' => 'beth@example.net'},
73 {'address' => 'carol@example.net',
74 'goto' => 'carol@example.net'}]
75 assert_equal(expected, actual)
76
77 rrm = RoundcubePrune.new(cfg)
78 actual = rrm.list_users()
79 expected = [User.new('alice@example.com'), User.new('adam@example.net')]
80 assert_equal(expected, actual)
81
82 # Booger and Jeremy should get pruned.
83 assert(maildir_exists('example.com/alice'))
84 assert(maildir_exists('example.net/adam'))
85 assert(!maildir_exists('example.com/booger'))
86 assert(!maildir_exists('example.com/jeremy'))
87 end
88
89 end