require 'pg'
require 'stringio'
-require 'test/unit'
+require "minitest/autorun"
+require 'minitest/unit'
# WARNING: Test output is dependent on the order these classes include
# certain modules; i.e. on the 'require' order.
require 'common/configuration'
+require 'common/domain'
+require 'common/user'
require "rm/plugins/agendav"
require "rm/plugins/davical"
require "rm/plugins/postfixadmin"
require "rm/rm_runner"
require "rm/rm_dummy_runner"
-
-class TestRm < Test::Unit::TestCase
-
+class TestRm < MiniTest::Unit::TestCase
TESTCONF_PATH = 'test/mailshears.test.conf.yml'
def connect_superuser()
def test_rm_user
cfg = Configuration.new(TESTCONF_PATH)
- argv = ["adam@example.net"]
+ users = [ User.new("adam@example.net") ]
output_buffer = StringIO.new()
$stdout = output_buffer
- plugin_class = RmPlugin.run(cfg, *argv)
+ RmPlugin.run(cfg, *users)
$stdout = STDOUT
actual = output_buffer.string()
expected =
- "AgendavRm - Removed user: adam@example.net " +
- "(Username: adam@example.net)\n" +
- "DavicalRm - User not found: adam@example.net\n" +
- "PostfixadminRm - Removed user: " +
- "adam@example.net (adam@example.net)\n" +
- "RoundcubeRm - Removed user: adam@example.net (User ID: 2)\n"
+ "AgendavRm - Removed user adam@example.net.\n" +
+ "DavicalRm - User adam@example.net not found.\n" +
+ "PostfixadminRm - Removed user adam@example.net.\n" +
+ "RoundcubeRm - Removed user adam@example.net (User ID: 2).\n"
assert_equal(expected, actual)
drm = DavicalRm.new(cfg)
actual = drm.list_users()
- expected = ['alice@example.com']
+ expected = [User.new('alice@example.com')]
assert_equal(expected, actual)
pfarm = PostfixadminRm.new(cfg)
actual = pfarm.list_users()
- expected = ['alice@example.com',
- 'bob@example.com',
- 'beth@example.net',
- 'carol@example.net']
+ expected = [User.new('alice@example.com'),
+ User.new('bob@example.com'),
+ User.new('beth@example.net'),
+ User.new('carol@example.net')]
assert_equal(expected, actual)
actual = pfarm.list_domains()
- expected = ['example.com', 'example.net']
+ expected = [Domain.new('example.com'), Domain.new('example.net')]
assert_equal(expected, actual)
actual = pfarm.list_aliases()
rrm = RoundcubeRm.new(cfg)
actual = rrm.list_users()
- expected = ['alice@example.com']
+ expected = [User.new('alice@example.com')]
assert_equal(expected, actual)
end
def test_rm_domain
- #
- # This must (and should) run after test_rm_user().
- #
cfg = Configuration.new(TESTCONF_PATH)
- argv = ["example.net"]
+ domains = [Domain.new("example.net")]
output_buffer = StringIO.new()
$stdout = output_buffer
- plugin_class = RmPlugin.run(cfg, *argv)
+ RmPlugin.run(cfg, *domains)
$stdout = STDOUT
actual = output_buffer.string()
expected =
- "AgendavRm - Removed domain: example.net (example.net)\n" +
- "DavicalRm - Domain not found: example.net\n" +
- "PostfixadminRm - Removed domain: example.net (example.net)\n" +
- "RoundcubeRm - Removed domain: example.net (example.net)\n"
+ "AgendavRm - Removed domain example.net.\n" +
+ "DavicalRm - Domain example.net not found.\n" +
+ "PostfixadminRm - Removed domain example.net.\n" +
+ "RoundcubeRm - Removed domain example.net.\n"
assert_equal(expected, actual)
drm = DavicalRm.new(cfg)
actual = drm.list_users()
- expected = ['alice@example.com']
+ expected = [User.new('alice@example.com')]
assert_equal(expected, actual)
pfarm = PostfixadminRm.new(cfg)
actual = pfarm.list_users()
- expected = ['alice@example.com', 'bob@example.com']
+ expected = [User.new('alice@example.com'),
+ User.new('bob@example.com')]
assert_equal(expected, actual)
actual = pfarm.list_domains()
- expected = ['example.com']
+ expected = [Domain.new('example.com')]
assert_equal(expected, actual)
actual = pfarm.list_aliases()
rrm = RoundcubeRm.new(cfg)
actual = rrm.list_users()
- expected = ['alice@example.com']
+ expected = [User.new('alice@example.com')]
assert_equal(expected, actual)
end