]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - test/mailshears_test.rb
lib,test: replace connection query() method with sync_exec{,_params}.
[mailshears.git] / test / mailshears_test.rb
index aea8dfcff8812d0802f55a3edfa16953f0c1b8b1..94f2f4903bd7894b505fa21e8a3ff340503ba668 100644 (file)
@@ -1,9 +1,17 @@
+# Without this, I get...
+#
+#   Warning: you should require 'minitest/autorun' instead.
+#   Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
+#
+# Whatever.
+gem 'minitest'
+require 'minitest/autorun'
+
 require 'common/configuration'
 require 'fileutils'
 require 'common/configuration'
 require 'fileutils'
-require 'minitest/unit'
 require 'pg'
 
 require 'pg'
 
-class MailshearsTest < MiniTest::Unit::TestCase
+class MailshearsTest < MiniTest::Test
   # This is that class that most (if not all) of our test cases will
   # inherit. It provides the automatic setup and teardown of the
   # filesystem and database that the test cases will exercise.
   # This is that class that most (if not all) of our test cases will
   # inherit. It provides the automatic setup and teardown of the
   # filesystem and database that the test cases will exercise.
@@ -32,13 +40,8 @@ class MailshearsTest < MiniTest::Unit::TestCase
     db_user = 'postgres'
     db_pass = nil
 
     db_user = 'postgres'
     db_pass = nil
 
-    connection = PGconn.connect(db_host,
-                                db_port,
-                                db_opts,
-                                db_tty,
-                                db_name,
-                                db_user,
-                                db_pass)
+    connection = PG::Connection.new(db_host, db_port, db_opts, db_tty,
+                                    db_name, db_user, db_pass)
 
     return connection
   end
 
     return connection
   end
@@ -65,33 +68,39 @@ class MailshearsTest < MiniTest::Unit::TestCase
     #
     # 1. agendav_test
     #
     #
     # 1. agendav_test
     #
-    #   +----------------------------+
-    #   |             prefs          |
-    #   +------------------+---------+
-    #   |  username        | options |
-    #   +------------------+---------+
-    #   | adam@example.net | herp    |
-    #   +------------------+---------+
+    #   +------------------------------+
+    #   |              prefs           |
+    #   +--------------------+---------+
+    #   |      username      | options |
+    #   +--------------------+---------+
+    #   |  adam@example.net  | herp    |
+    #   +--------------------+---------+
+    #   | booger@example.com | herp    |
+    #   +------------------  +---------+
     #
     #
     #
     #
-    #   +------------------------------------------------------+
-    #   |                        shared                        |
-    #   +-----+------------------+----------+------------------+
-    #   | sid |    user_from     | calendar |    user_which    |
-    #   +-----+------------------+----------+------------------+
-    #   |   1 | adam@example.net | derp     | beth@example.net |
-    #   +-----+------------------+----------+------------------+
+    #   +---------------------------------------------------------------------------------------------------------------------+
+    #   |                                                       shares                                                        |
+    #   +-----+-----------------------------------+---------------------------------------------------+-----------------------+
+    #   | sid |              owner                |                      calendar                     |          with         |
+    #   +-----+-----------------------------------+---------------------------------------------------+-----------------------+
+    #   |   1 | /caldav.php/adam%40example.net/   | /caldav.php/adam%40example.net/calendar-default   | /beth%40example.net/  |
+    #   +-----+-----------------------------------+---------------------------------------------------+-----------------------+
+    #   |   2 | /caldav.php/booger%40example.com/ | /caldav.php/booger%40example.com/calendar-default | /carol%40example.net/ |
+    #   +-----+-----------------------------------+---------------------------------------------------+-----------------------+
     #
     #
     # 2. davical_test
     #
     #
     #
     # 2. davical_test
     #
-    #   +-------------------------------------------------------+
-    #   |                        usr                            |
-    #   +---------+--------+----------------+-------------------+
-    #   | user_no | active |    joined      |     username      |
-    #   +---------+--------+----------------+-------------------+
-    #   |      17 | t      | 2014-01-04 ... | alice@example.com |
-    #   +---------+--------+----------------+-------------------+
+    #   +--------------------------------------------------------+
+    #   |                         usr                            |
+    #   +---------+--------+----------------+--------------------+
+    #   | user_no | active |    joined      |      username      |
+    #   +---------+--------+----------------+--------------------+
+    #   |      17 | t      | 2014-01-04 ... | alice@example.com  |
+    #   +---------+--------+----------------+--------------------+
+    #   |      18 | t      | 2014-01-04 ... | booger@example.com |
+    #   +---------+--------+----------------+--------------------+
     #
     #
     #   +-----------------------------------------+
     #
     #
     #   +-----------------------------------------+
@@ -101,6 +110,8 @@ class MailshearsTest < MiniTest::Unit::TestCase
     #   +---------+--------------+----------------+
     #   |      17 | dumb setting | its dumb value |
     #   +---------+--------------+----------------+
     #   +---------+--------------+----------------+
     #   |      17 | dumb setting | its dumb value |
     #   +---------+--------------+----------------+
+    #   |      18 | dumb setting | its dumb value |
+    #   +---------+--------------+----------------+
     #
     #
     # 3. postfixadmin_test
     #
     #
     # 3. postfixadmin_test
@@ -135,21 +146,24 @@ class MailshearsTest < MiniTest::Unit::TestCase
     #   +-------------------+-------------+------------+
     #
     #
     #   +-------------------+-------------+------------+
     #
     #
-    #   +------------------------------------------------------+
-    #   |                          alias                       |
-    #   +-------------------+-------------------+--------------+
-    #   |     address       |       goto        |   domain     |
-    #   +-------------------+-------------------+--------------+
-    #   | alice@example.com | alice@example.com | example.com  |
-    #   +-------------------+-------------------+--------------+
-    #   | bob@example.com   | bob@example.com   | example.com  |
-    #   +-------------------+-------------------+--------------+
-    #   | adam@example.net  | adam@example.net  | example.net  |
-    #   +-------------------+-------------------+--------------+
-    #   | beth@example.net  | beth@example.net  | example.net  |
-    #   +-------------------+-------------------+--------------+
-    #   | carol@example.net | carol@example.net | example.net  |
-    #   +-------------------+-------------------+--------------+
+    #   +-------------------------------------------------------+
+    #   |                          alias                        |
+    #   +-------------------+--------------------+--------------+
+    #   |     address       |       goto         |   domain     |
+    #   +-------------------+--------------------+--------------+
+    #   | alice@example.com | alice@example.com, | example.com  |
+    #   |                   | adam@example.net,  |              |
+    #   |                   | bob@example.com,   |              |
+    #   |                   | carol@example.net  |              |
+    #   +-------------------+--------------------+--------------+
+    #   | bob@example.com   | bob@example.com    | example.com  |
+    #   +-------------------+--------------------+--------------+
+    #   | adam@example.net  | adam@example.net   | example.net  |
+    #   +-------------------+--------------------+--------------+
+    #   | beth@example.net  | beth@example.net   | example.net  |
+    #   +-------------------+--------------------+--------------+
+    #   | carol@example.net | carol@example.net  | example.net  |
+    #   +-------------------+--------------------+--------------+
     #
     #
     #   +---------------------------------+
     #
     #
     #   +---------------------------------+
@@ -165,13 +179,19 @@ class MailshearsTest < MiniTest::Unit::TestCase
     # 4. roundcube_test
     #
     #
     # 4. roundcube_test
     #
     #
-    #   +---------+-------------------+
-    #   | user_id |     username      |
-    #   +---------+-------------------+
-    #   |       1 | alice@example.com |
-    #   +---------+-------------------+
-    #   |       2 | adam@example.net  |
-    #   +---------+-------------------+
+    #   +---------+--------------------+
+    #   | user_id |     username       |
+    #   +---------+--------------------+
+    #   |       1 | alice@example.com  |
+    #   +---------+--------------------+
+    #   |       2 | booger@example.com |
+    #   +---------+--------------------+
+    #   |       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()
 
 
     cfg = configuration()
 
@@ -188,7 +208,7 @@ class MailshearsTest < MiniTest::Unit::TestCase
       plugin_dbname = cfg.send("#{plugin}_dbname")
       next if plugin_dbname.nil? # Skip the dovecot plugin
       query = "CREATE DATABASE #{plugin_dbname};"
       plugin_dbname = cfg.send("#{plugin}_dbname")
       next if plugin_dbname.nil? # Skip the dovecot plugin
       query = "CREATE DATABASE #{plugin_dbname};"
-      connection.query(query)
+      connection.sync_exec(query)
 
       plugin_dbhost = cfg.send("#{plugin}_dbhost")
       plugin_dbport = cfg.send("#{plugin}_dbport")
 
       plugin_dbhost = cfg.send("#{plugin}_dbhost")
       plugin_dbport = cfg.send("#{plugin}_dbport")
@@ -197,18 +217,15 @@ class MailshearsTest < MiniTest::Unit::TestCase
       plugin_dbuser = cfg.send("#{plugin}_dbuser")
       plugin_dbpass = cfg.send("#{plugin}_dbpass")
 
       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)
+      plugin_conn = PG::Connection.new(plugin_dbhost, plugin_dbport,
+                                       plugin_dbopts, plugin_dbtty,
+                                       plugin_dbname, plugin_dbuser,
+                                       plugin_dbpass)
 
       sql = File.open("test/sql/#{plugin}.sql").read()
 
       sql = File.open("test/sql/#{plugin}.sql").read()
-      plugin_conn.query(sql)
+      plugin_conn.sync_exec(sql)
       sql = File.open("test/sql/#{plugin}-fixtures.sql").read()
       sql = File.open("test/sql/#{plugin}-fixtures.sql").read()
-      plugin_conn.query(sql)
+      plugin_conn.sync_exec(sql)
       plugin_conn.close()
     end
 
       plugin_conn.close()
     end
 
@@ -221,17 +238,21 @@ class MailshearsTest < MiniTest::Unit::TestCase
     cfg = configuration()
     connection = connect_superuser()
 
     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
     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};"
-      connection.query(query)
+      query = "DROP DATABASE IF EXISTS #{plugin_dbname};"
+      connection.sync_exec(query)
     end
 
     connection.close()
 
     # Get rid of the maildirs.
     end
 
     connection.close()
 
     # Get rid of the maildirs.
-    FileUtils.rm_r(cfg.dovecot_mail_root())
+    FileUtils.rm_rf(cfg.dovecot_mail_root())
   end
 
 end
   end
 
 end