]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Make pruning use the correct config and clean up *before* running tests, too.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 5 Nov 2015 00:08:46 +0000 (19:08 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 5 Nov 2015 00:08:46 +0000 (19:08 -0500)
lib/common/plugin.rb
lib/common/runner.rb
lib/mv/mv_dummy_runner.rb
lib/mv/mv_runner.rb
lib/prune/prune_dummy_runner.rb
lib/prune/prune_runner.rb
lib/rm/rm_dummy_runner.rb
lib/rm/rm_runner.rb
test/mailshears_test.rb

index 702b621ff5da9c1ee18ccbd0fd29352950a63386..dba8becb2756c0324ecd252adb9b3602de218afb 100644 (file)
@@ -46,7 +46,7 @@ module Plugin
         # The splat passes the correct (we hope) number of arguments to the
         # appropriate runner. The Rm(Dummy)Runner have splats on their
         # *target arguments as well, to turn ARGV back into an array.
-        runner.run(plugin, *args)
+        runner.run(cfg, plugin, *args)
       end
     end
   end
index 32f2b3ecf8bb0354408fb7fbe46596155e2baf3a..01fcc176e3cedd62935a9b81c5b3657437abd610 100644 (file)
@@ -1,6 +1,6 @@
 module Runner
 
-  def run(plugin, targets)
+  def run(cfg, plugin, targets)
     raise NotImplementedError
   end
 
index 52db27be6f0082051ee17565c7ee7b8b5c61b31a..7db7c06c9536947b32ad05305fa8601fc7d22da5 100644 (file)
@@ -3,7 +3,7 @@ require 'common/runner'
 class MvDummyRunner
   include Runner
 
-  def run(plugin, src, dst)
+  def run(cfg, plugin, src, dst)
 
     if src.is_a?(Domain) or dst.is_a?(Domain) then
       msg = 'only users can be moved'
index 6da6f6d3bb7fd6311d6e27915d5c10d230f981f1..0e5e909e268944c25f2003e82eceb84bcc5b7bda 100644 (file)
@@ -5,7 +5,7 @@ require 'common/runner'
 class MvRunner
   include Runner
 
-  def run(plugin, src, dst)
+  def run(cfg, plugin, src, dst)
 
     if src.is_a?(Domain) or dst.is_a?(Domain) then
       msg = 'only users can be moved'
index 64c2606979aad0298cd94b3547d9703da78f21dd..d488f7ea155c7a77633212aeee3776d844921bbe 100644 (file)
@@ -5,11 +5,10 @@ require 'rm/rm_dummy_runner'
 class PruneDummyRunner
   include Runner
 
-  def run(plugin)
+  def run(cfg, plugin)
     # We don't want to check the PostfixAdmin database against itself.
     return if plugin.class == PostfixadminPrune
 
-    cfg = Configuration.new()
     pfa = PostfixadminPrune.new(cfg)
 
     db_users = pfa.list_users()
@@ -19,7 +18,7 @@ class PruneDummyRunner
     leftovers += plugin.get_leftover_domains(db_domains)
 
     rm_dummy_runner = RmDummyRunner.new()
-    rm_dummy_runner.run(plugin, *leftovers)
+    rm_dummy_runner.run(cfg, plugin, *leftovers)
   end
 
 end
index 8ae8ad218bcbc402e167509dca190ab62cbec5fb..fbad8e8f11c4e5cb71f7dcc2ccbdc0caf7ad40b5 100644 (file)
@@ -5,11 +5,10 @@ require 'rm/rm_runner'
 class PruneRunner
   include Runner
 
-  def run(plugin)
+  def run(cfg, plugin)
     # We don't want to check the PostfixAdmin database against itself.
     return if plugin.class == PostfixadminPrune
 
-    cfg = Configuration.new()
     pfa = PostfixadminPrune.new(cfg)
 
     db_users = pfa.list_users()
@@ -19,7 +18,7 @@ class PruneRunner
     leftovers += plugin.get_leftover_domains(db_domains)
 
     rm_runner = RmRunner.new()
-    rm_runner.run(plugin, *leftovers)
+    rm_runner.run(cfg, plugin, *leftovers)
   end
 
 end
index 2ab25e80a3e402f5ba3c21214b30a768d6c2cd2c..62d9b628dd7db4b69c27a0804acae27e73325385 100644 (file)
@@ -3,7 +3,7 @@ require 'common/runner'
 class RmDummyRunner
   include Runner
 
-  def run(plugin, *targets)
+  def run(cfg, plugin, *targets)
     targets.each do |target|
       target_description = plugin.describe(target)
       msg =  "Would remove #{target.class.to_s().downcase()} #{target}"
index 2df8410c5ea9d6d3d65d2565ec9cc00552d7b1f0..a19004a7a5440fcd23bb22173d3e5fe4d963ed76 100644 (file)
@@ -4,7 +4,7 @@ require 'common/runner'
 class RmRunner
   include Runner
 
-  def run(plugin, *targets)
+  def run(cfg, plugin, *targets)
     targets.each do |target|
       remove_target(plugin, target)
     end
index b4ba814f014e2dd83919f07200ac04dc1804fd18..8e80c063f0a3a07092996d2eab49f82d50db5d8d 100644 (file)
@@ -32,13 +32,8 @@ class MailshearsTest < MiniTest::Unit::TestCase
     db_user = 'postgres'
     db_pass = nil
 
-    connection = PGconn.connect(db_host,
-                                db_port,
-                                db_opts,
-                                db_tty,
-                                db_name,
-                                db_user,
-                                db_pass)
+    connection = PGconn.connect(db_host, db_port, db_opts, db_tty,
+                                db_name, db_user, db_pass)
 
     return connection
   end
@@ -183,6 +178,10 @@ class MailshearsTest < MiniTest::Unit::TestCase
     #   |       3 | adam@example.net   |
     #   +---------+--------------------+
 
+    # First make sure we get rid of everything so we don't get random
+    # failures from databases and directories that already exist.
+    teardown()
+
     cfg = configuration()
 
     # First create the "mail directories".
@@ -207,12 +206,8 @@ class MailshearsTest < MiniTest::Unit::TestCase
       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_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()
@@ -231,17 +226,21 @@ class MailshearsTest < MiniTest::Unit::TestCase
     cfg = configuration()
     connection = connect_superuser()
 
+    # Don't emit notices about missing tables. Why this happens when I
+    # explicitly say IF EXISTS is beyond me.
+    connection.set_notice_processor{}
+
     cfg.plugins.each do |plugin|
       plugin_dbname = cfg.send("#{plugin}_dbname")
       next if plugin_dbname.nil? # Skip the dovecot plugin
-      query = "DROP DATABASE #{plugin_dbname};"
+      query = "DROP DATABASE IF EXISTS #{plugin_dbname};"
       connection.query(query)
     end
 
     connection.close()
 
     # Get rid of the maildirs.
-    FileUtils.rm_r(cfg.dovecot_mail_root())
+    FileUtils.rm_rf(cfg.dovecot_mail_root())
   end
 
 end