From a731b98f97194b8882c42d3c2b27de75f60d6b05 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 4 Nov 2015 19:08:46 -0500 Subject: [PATCH] Make pruning use the correct config and clean up *before* running tests, too. --- lib/common/plugin.rb | 2 +- lib/common/runner.rb | 2 +- lib/mv/mv_dummy_runner.rb | 2 +- lib/mv/mv_runner.rb | 2 +- lib/prune/prune_dummy_runner.rb | 5 ++--- lib/prune/prune_runner.rb | 5 ++--- lib/rm/rm_dummy_runner.rb | 2 +- lib/rm/rm_runner.rb | 2 +- test/mailshears_test.rb | 29 ++++++++++++++--------------- 9 files changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index 702b621..dba8bec 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -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 diff --git a/lib/common/runner.rb b/lib/common/runner.rb index 32f2b3e..01fcc17 100644 --- a/lib/common/runner.rb +++ b/lib/common/runner.rb @@ -1,6 +1,6 @@ module Runner - def run(plugin, targets) + def run(cfg, plugin, targets) raise NotImplementedError end diff --git a/lib/mv/mv_dummy_runner.rb b/lib/mv/mv_dummy_runner.rb index 52db27b..7db7c06 100644 --- a/lib/mv/mv_dummy_runner.rb +++ b/lib/mv/mv_dummy_runner.rb @@ -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' diff --git a/lib/mv/mv_runner.rb b/lib/mv/mv_runner.rb index 6da6f6d..0e5e909 100644 --- a/lib/mv/mv_runner.rb +++ b/lib/mv/mv_runner.rb @@ -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' diff --git a/lib/prune/prune_dummy_runner.rb b/lib/prune/prune_dummy_runner.rb index 64c2606..d488f7e 100644 --- a/lib/prune/prune_dummy_runner.rb +++ b/lib/prune/prune_dummy_runner.rb @@ -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 diff --git a/lib/prune/prune_runner.rb b/lib/prune/prune_runner.rb index 8ae8ad2..fbad8e8 100644 --- a/lib/prune/prune_runner.rb +++ b/lib/prune/prune_runner.rb @@ -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 diff --git a/lib/rm/rm_dummy_runner.rb b/lib/rm/rm_dummy_runner.rb index 2ab25e8..62d9b62 100644 --- a/lib/rm/rm_dummy_runner.rb +++ b/lib/rm/rm_dummy_runner.rb @@ -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}" diff --git a/lib/rm/rm_runner.rb b/lib/rm/rm_runner.rb index 2df8410..a19004a 100644 --- a/lib/rm/rm_runner.rb +++ b/lib/rm/rm_runner.rb @@ -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 diff --git a/test/mailshears_test.rb b/test/mailshears_test.rb index b4ba814..8e80c06 100644 --- a/test/mailshears_test.rb +++ b/test/mailshears_test.rb @@ -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 -- 2.44.2