Fix broken nesting in lib/mv/plugins/postfixadmin.rb.
[mailshears.git] / test / test_rm.rb
index 3f61221e487178fbb77d4993748a9c689af05b1c..1d424619b76561c054ccd34f86679ab672d19036 100644 (file)
@@ -1,82 +1,21 @@
-require 'pg'
-require 'stringio'
-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/plugins/roundcube"
-require "rm/rm_runner"
-require "rm/rm_dummy_runner"
-
-class TestRm < MiniTest::Unit::TestCase
-  TESTCONF_PATH = 'test/mailshears.test.conf.yml'
-
-  def connect_superuser()
-    db_host = 'localhost'
-    db_port = 5432
-    db_opts = nil
-    db_tty = nil
-    db_name = 'postgres'
-    db_user = 'postgres'
-    db_pass = nil
-
-    connection = PGconn.connect(db_host,
-                                db_port,
-                                db_opts,
-                                db_tty,
-                                db_name,
-                                db_user,
-                                db_pass)
-
-    return connection
-  end
-
-  def setup
-    # Create databases using from the test configuration file.
-    cfg = Configuration.new(TESTCONF_PATH)
-    connection = connect_superuser()
-
-    cfg.plugins.each do |plugin|
-      plugin_dbname = cfg.send("#{plugin}_dbname")
-      query = "CREATE DATABASE #{plugin_dbname};"
-      connection.query(query)
-
-      plugin_dbhost = cfg.send("#{plugin}_dbhost")
-      plugin_dbport = cfg.send("#{plugin}_dbport")
-      plugin_dbopts = cfg.send("#{plugin}_dbopts")
-      plugin_dbtty  = cfg.send("#{plugin}_dbtty")
-      plugin_dbuser = cfg.send("#{plugin}_dbuser")
-      plugin_dbpass = cfg.send("#{plugin}_dbpass")
-
-      plugin_conn = PGconn.connect(plugin_dbhost,
-                                   plugin_dbport,
-                                   plugin_dbopts,
-                                   plugin_dbtty,
-                                   plugin_dbname,
-                                   plugin_dbuser,
-                                   plugin_dbpass)
-
-      sql = File.open("test/sql/#{plugin}.sql").read()
-      plugin_conn.query(sql)
-      sql = File.open("test/sql/#{plugin}-fixtures.sql").read()
-      plugin_conn.query(sql)
-      plugin_conn.close()
-    end
-
-    connection.close()
-  end
+require 'mailshears_test'
+require 'minitest/autorun'
+require 'rm/plugins/agendav'
+require 'rm/plugins/davical'
+require 'rm/plugins/dovecot'
+require 'rm/plugins/postfixadmin'
+require 'rm/plugins/roundcube'
+require 'rm/rm_runner'
 
 
+class TestRm < MailshearsTest
 
   def test_rm_user
-    cfg = Configuration.new(TESTCONF_PATH)
+    cfg = configuration()
     users = [ User.new("adam@example.net") ]
 
     output_buffer = StringIO.new()
@@ -90,8 +29,10 @@ class TestRm < MiniTest::Unit::TestCase
     expected =
       "AgendavRm - Removed user adam@example.net.\n" +
       "DavicalRm - User adam@example.net not found.\n" +
+      "DovecotRm - Removed user adam@example.net " +
+        "(#{cfg.dovecot_mail_root}/example.net/adam).\n" +
       "PostfixadminRm - Removed user adam@example.net.\n" +
-      "RoundcubeRm - Removed user adam@example.net (User ID: 2).\n"
+      "RoundcubeRm - Removed user adam@example.net (User ID: 3).\n"
 
     assert_equal(expected, actual)
 
@@ -99,12 +40,12 @@ class TestRm < MiniTest::Unit::TestCase
 
     arm = AgendavRm.new(cfg)
     actual = arm.list_users()
-    expected = []
+    expected = [User.new('booger@example.com')]
     assert_equal(expected, actual)
 
     drm = DavicalRm.new(cfg)
     actual = drm.list_users()
-    expected = [User.new('alice@example.com')]
+    expected = [User.new('alice@example.com'), User.new('booger@example.com')]
     assert_equal(expected, actual)
 
     pfarm = PostfixadminRm.new(cfg)
@@ -132,13 +73,19 @@ class TestRm < MiniTest::Unit::TestCase
 
     rrm = RoundcubeRm.new(cfg)
     actual = rrm.list_users()
-    expected = [User.new('alice@example.com')]
+    expected = [User.new('alice@example.com'), User.new('booger@example.com')]
     assert_equal(expected, actual)
+
+    # Check that adam's directory is gone but that the rest remain.
+    assert(maildir_exists('example.com/alice'))
+    assert(maildir_exists('example.com/booger'))
+    assert(maildir_exists('example.com/jeremy'))
+    assert(!maildir_exists('example.net/adam'))
   end
 
 
   def test_rm_domain
-    cfg = Configuration.new(TESTCONF_PATH)
+    cfg = configuration()
     domains = [Domain.new("example.net")]
 
     output_buffer = StringIO.new()
@@ -152,6 +99,8 @@ class TestRm < MiniTest::Unit::TestCase
     expected =
       "AgendavRm - Removed domain example.net.\n" +
       "DavicalRm - Domain example.net not found.\n" +
+      "DovecotRm - Removed domain example.net " +
+        "(#{cfg.dovecot_mail_root}/example.net).\n" +
       "PostfixadminRm - Removed domain example.net.\n" +
       "RoundcubeRm - Removed domain example.net.\n"
 
@@ -161,12 +110,12 @@ class TestRm < MiniTest::Unit::TestCase
 
     arm = AgendavRm.new(cfg)
     actual = arm.list_users()
-    expected = []
+    expected = [User.new('booger@example.com')]
     assert_equal(expected, actual)
 
     drm = DavicalRm.new(cfg)
     actual = drm.list_users()
-    expected = [User.new('alice@example.com')]
+    expected = [User.new('alice@example.com'), User.new('booger@example.com')]
     assert_equal(expected, actual)
 
     pfarm = PostfixadminRm.new(cfg)
@@ -188,23 +137,15 @@ class TestRm < MiniTest::Unit::TestCase
 
     rrm = RoundcubeRm.new(cfg)
     actual = rrm.list_users()
-    expected = [User.new('alice@example.com')]
+    expected = [User.new('alice@example.com'), User.new('booger@example.com')]
     assert_equal(expected, actual)
-  end
 
-
-
-  def teardown
-    cfg = Configuration.new(TESTCONF_PATH)
-    connection = connect_superuser()
-
-    cfg.plugins.each do |plugin|
-      plugin_dbname = cfg.send("#{plugin}_dbname")
-      query = "DROP DATABASE #{plugin_dbname};"
-      connection.query(query)
-    end
-
-    connection.close()
+    # Check that example.net's directory is gone but that the rest remain.
+    assert(maildir_exists('example.com/alice'))
+    assert(maildir_exists('example.com/booger'))
+    assert(maildir_exists('example.com/jeremy'))
+    assert(!maildir_exists('example.net'))
   end
 
+
 end