]>
gitweb.michael.orlitzky.com - mailshears.git/blob - test/mailshears_test.rb
aea8dfcff8812d0802f55a3edfa16953f0c1b8b1
1 require 'common/configuration'
3 require 'minitest/unit'
6 class MailshearsTest
< MiniTest
::Unit::TestCase
7 # This is that class that most (if not all) of our test cases will
8 # inherit. It provides the automatic setup and teardown of the
9 # filesystem and database that the test cases will exercise.
12 # Return the test config object.
13 return Configuration
.new('test/mailshears.test.conf.yml')
16 def maildir_exists(dir
)
17 # Check if the given mail directory of the form "example.com/user"
20 return File
.directory
?("#{cfg.dovecot_mail_root()}/#{dir}")
23 def connect_superuser()
24 # Connect to the database (specified in the test configuration) as
25 # the superuser. Your local configuration is expected to be such
26 # that this "just works."
35 connection
= PGconn
.connect(db_host
,
47 # Connect to the database specified in the test configutation as
48 # the super user. Then, run all of the SQL scripts contained in
49 # test/sql. These scripts create the tables for the plugins listed
50 # in the test configuration, and then create some sample data.
52 # Here is the full list of what gets created. Every test case
53 # inheriting from this class can expect this schema and data to
54 # exist. The filesystem entries are located beneath mail_root from
55 # the configuration file.
60 # * example.com/booger
61 # * example.com/jeremy
68 # +----------------------------+
70 # +------------------+---------+
71 # | username | options |
72 # +------------------+---------+
73 # | adam@example.net | herp |
74 # +------------------+---------+
77 # +------------------------------------------------------+
79 # +-----+------------------+----------+------------------+
80 # | sid | user_from | calendar | user_which |
81 # +-----+------------------+----------+------------------+
82 # | 1 | adam@example.net | derp | beth@example.net |
83 # +-----+------------------+----------+------------------+
88 # +-------------------------------------------------------+
90 # +---------+--------+----------------+-------------------+
91 # | user_no | active | joined | username |
92 # +---------+--------+----------------+-------------------+
93 # | 17 | t | 2014-01-04 ... | alice@example.com |
94 # +---------+--------+----------------+-------------------+
97 # +-----------------------------------------+
99 # +---------+--------------+----------------+
100 # | user_no | setting_name | setting_value |
101 # +---------+--------------+----------------+
102 # | 17 | dumb setting | its dumb value |
103 # +---------+--------------+----------------+
106 # 3. postfixadmin_test
121 # +----------------------------------------------+
123 # +-------------------+-------------+------------+
124 # | username | domain | local_part |
125 # +-------------------+-------------+------------+
126 # | alice@example.com | example.com | alice |
127 # +-------------------+-------------+------------+
128 # | bob@example.com | example.com | bob |
129 # +-------------------+-------------+------------+
130 # | adam@example.net | example.net | adam |
131 # +-------------------+-------------+------------+
132 # | beth@example.net | example.net | beth |
133 # +-------------------+-------------+------------+
134 # | carol@example.net | example.net | carol |
135 # +-------------------+-------------+------------+
138 # +------------------------------------------------------+
140 # +-------------------+-------------------+--------------+
141 # | address | goto | domain |
142 # +-------------------+-------------------+--------------+
143 # | alice@example.com | alice@example.com | example.com |
144 # +-------------------+-------------------+--------------+
145 # | bob@example.com | bob@example.com | example.com |
146 # +-------------------+-------------------+--------------+
147 # | adam@example.net | adam@example.net | example.net |
148 # +-------------------+-------------------+--------------+
149 # | beth@example.net | beth@example.net | example.net |
150 # +-------------------+-------------------+--------------+
151 # | carol@example.net | carol@example.net | example.net |
152 # +-------------------+-------------------+--------------+
155 # +---------------------------------+
157 # +-------------------+-------------+
158 # | username | domain |
159 # +-------------------+-------------+
160 # | admin@example.com | example.com |
161 # +-------------------+-------------+
162 # | admin@example.com | example.net |
163 # +-------------------+-------------+
168 # +---------+-------------------+
169 # | user_id | username |
170 # +---------+-------------------+
171 # | 1 | alice@example.com |
172 # +---------+-------------------+
173 # | 2 | adam@example.net |
174 # +---------+-------------------+
176 cfg
= configuration()
178 # First create the "mail directories".
179 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/alice")
180 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/booger")
181 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/jeremy")
182 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.net/adam")
184 # Now the databases and their content.
185 connection
= connect_superuser()
187 cfg
.plugins
.each
do |plugin
|
188 plugin_dbname
= cfg
.send("#{plugin}_dbname")
189 next if plugin_dbname
.nil? # Skip the dovecot plugin
190 query
= "CREATE DATABASE #{plugin_dbname};"
191 connection
.query(query
)
193 plugin_dbhost
= cfg
.send("#{plugin}_dbhost")
194 plugin_dbport
= cfg
.send("#{plugin}_dbport")
195 plugin_dbopts
= cfg
.send("#{plugin}_dbopts")
196 plugin_dbtty
= cfg
.send("#{plugin}_dbtty")
197 plugin_dbuser
= cfg
.send("#{plugin}_dbuser")
198 plugin_dbpass
= cfg
.send("#{plugin}_dbpass")
200 plugin_conn
= PGconn
.connect(plugin_dbhost
,
208 sql
= File
.open("test/sql/#{plugin}.sql").read()
209 plugin_conn
.query(sql
)
210 sql
= File
.open("test/sql/#{plugin}-fixtures.sql").read()
211 plugin_conn
.query(sql
)
220 # Drop all of the databases that were created in setup().
221 cfg
= configuration()
222 connection
= connect_superuser()
224 cfg
.plugins
.each
do |plugin
|
225 plugin_dbname
= cfg
.send("#{plugin}_dbname")
226 next if plugin_dbname
.nil? # Skip the dovecot plugin
227 query
= "DROP DATABASE #{plugin_dbname};"
228 connection
.query(query
)
233 # Get rid of the maildirs.
234 FileUtils
.rm_r(cfg
.dovecot_mail_root())