Switch to MiniTest and update the test output.
[mailshears.git] / test / test_rm.rb
index 01d2c1c598adc163a7a0f5d606482b211049f652..3f61221e487178fbb77d4993748a9c689af05b1c 100644 (file)
@@ -1,10 +1,13 @@
 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"
@@ -12,9 +15,7 @@ require "rm/plugins/roundcube"
 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()
@@ -76,23 +77,21 @@ class TestRm < Test::Unit::TestCase
 
   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)
 
@@ -105,19 +104,19 @@ class TestRm < Test::Unit::TestCase
 
     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()
@@ -133,31 +132,28 @@ class TestRm < Test::Unit::TestCase
 
     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)
 
@@ -170,16 +166,17 @@ class TestRm < Test::Unit::TestCase
 
     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()
@@ -191,7 +188,7 @@ class TestRm < Test::Unit::TestCase
 
     rrm = RoundcubeRm.new(cfg)
     actual = rrm.list_users()
-    expected = ['alice@example.com']
+    expected = [User.new('alice@example.com')]
     assert_equal(expected, actual)
   end