Begin cleaning up the test code to add some prune/mv cases.
[mailshears.git] / test / test_rm.rb
index 3f61221e487178fbb77d4993748a9c689af05b1c..09ebe2e37c4faefcb5ff68932c92883b6ab6fad8 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'
+require 'rm/rm_dummy_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()
@@ -87,9 +26,12 @@ class TestRm < MiniTest::Unit::TestCase
 
     actual = output_buffer.string()
 
+    mail_root = cfg.send('mail_root')
     expected =
       "AgendavRm - Removed user adam@example.net.\n" +
       "DavicalRm - User adam@example.net not found.\n" +
+      "DovecotRm - Removed user adam@example.net " +
+        "(#{mail_root}/example.net/adam).\n" +
       "PostfixadminRm - Removed user adam@example.net.\n" +
       "RoundcubeRm - Removed user adam@example.net (User ID: 2).\n"
 
@@ -134,11 +76,17 @@ class TestRm < MiniTest::Unit::TestCase
     actual = rrm.list_users()
     expected = [User.new('alice@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()
@@ -149,9 +97,12 @@ class TestRm < MiniTest::Unit::TestCase
 
     actual = output_buffer.string()
 
+    mail_root = cfg.send('mail_root')
     expected =
       "AgendavRm - Removed domain example.net.\n" +
       "DavicalRm - Domain example.net not found.\n" +
+      "DovecotRm - Removed domain example.net " +
+        "(#{mail_root}/example.net).\n" +
       "PostfixadminRm - Removed domain example.net.\n" +
       "RoundcubeRm - Removed domain example.net.\n"
 
@@ -190,21 +141,13 @@ class TestRm < MiniTest::Unit::TestCase
     actual = rrm.list_users()
     expected = [User.new('alice@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