+++ /dev/null
-require 'pg'
-require 'test/unit'
-
-require 'common/configuration'
-
-class RmAccountTest < Test::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 test_single_rm
- cfg = Configuration.new(TESTCONF_PATH)
- argv = ["adam@example.net"]
-
- # Load each of the plugins that we'll need.
- cfg.plugins.each do |plugin_file|
- require "rm/plugins/#{plugin_file}"
- end
-
- # And the runners.
- require "rm/rm_runner"
- require "rm/rm_dummy_runner"
-
- require 'stringio'
- output_buffer = StringIO.new()
-
- $stdout = output_buffer
- plugin_class = RmPlugin.run(cfg, *argv)
- $stdout = STDOUT
-
- actual = output_buffer.string()
-
- expected = "PostfixadminRm - Removed user: " +
- "adam@example.net (adam@example.net)\n" +
- "RoundcubeRm - Removed user: adam@example.net (User ID: 2)\n" +
- "AgendavRm - Removed user: adam@example.net " +
- "(Username: adam@example.net)\n" +
- "DavicalRm - User not found: adam@example.net\n"
- assert(actual == expected)
- 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
-
-
- def teardown
- # Destroy 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 = "DROP DATABASE #{plugin_dbname};"
- connection.query(query)
- end
-
- connection.close()
- end
-
-end