]>
gitweb.michael.orlitzky.com - mailshears.git/blob - test/mailshears_test.rb
1 # Without this, I get...
3 # Warning: you should require 'minitest/autorun' instead.
4 # Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
8 require 'minitest/autorun'
10 require 'common/configuration'
14 class MailshearsTest
< MiniTest
::Test
15 # This is that class that most (if not all) of our test cases will
16 # inherit. It provides the automatic setup and teardown of the
17 # filesystem and database that the test cases will exercise.
20 # Return the test config object.
21 return Configuration
.new('test/mailshears.test.conf.yml')
24 def maildir_exists(dir
)
25 # Check if the given mail directory of the form "example.com/user"
28 return File
.directory
?("#{cfg.dovecot_mail_root()}/#{dir}")
31 def connect_superuser()
32 # Connect to the database (specified in the test configuration) as
33 # the superuser. Your local configuration is expected to be such
34 # that this "just works."
39 :dbname => 'postgres',
43 connection
= PG
::Connection.new(db_hash
)
49 # Connect to the database specified in the test configutation as
50 # the super user. Then, run all of the SQL scripts contained in
51 # test/sql. These scripts create the tables for the plugins listed
52 # in the test configuration, and then create some sample data.
54 # Here is the full list of what gets created. Every test case
55 # inheriting from this class can expect this schema and data to
56 # exist. The filesystem entries are located beneath mail_root from
57 # the configuration file.
62 # * example.com/booger
63 # * example.com/jeremy
70 # +------------------------------+
72 # +--------------------+---------+
73 # | username | options |
74 # +--------------------+---------+
75 # | adam@example.net | herp |
76 # +--------------------+---------+
77 # | booger@example.com | herp |
78 # +------------------ +---------+
81 # +---------------------------------------------------------------------------------------------------------------------+
83 # +-----+-----------------------------------+---------------------------------------------------+-----------------------+
84 # | sid | owner | calendar | with |
85 # +-----+-----------------------------------+---------------------------------------------------+-----------------------+
86 # | 1 | /caldav.php/adam%40example.net/ | /caldav.php/adam%40example.net/calendar-default | /beth%40example.net/ |
87 # +-----+-----------------------------------+---------------------------------------------------+-----------------------+
88 # | 2 | /caldav.php/booger%40example.com/ | /caldav.php/booger%40example.com/calendar-default | /carol%40example.net/ |
89 # +-----+-----------------------------------+---------------------------------------------------+-----------------------+
94 # +--------------------------------------------------------+
96 # +---------+--------+----------------+--------------------+
97 # | user_no | active | joined | username |
98 # +---------+--------+----------------+--------------------+
99 # | 17 | t | 2014-01-04 ... | alice@example.com |
100 # +---------+--------+----------------+--------------------+
101 # | 18 | t | 2014-01-04 ... | booger@example.com |
102 # +---------+--------+----------------+--------------------+
105 # +-----------------------------------------+
107 # +---------+--------------+----------------+
108 # | user_no | setting_name | setting_value |
109 # +---------+--------------+----------------+
110 # | 17 | dumb setting | its dumb value |
111 # +---------+--------------+----------------+
112 # | 18 | dumb setting | its dumb value |
113 # +---------+--------------+----------------+
116 # 3. postfixadmin_test
131 # +----------------------------------------------+
133 # +-------------------+-------------+------------+
134 # | username | domain | local_part |
135 # +-------------------+-------------+------------+
136 # | alice@example.com | example.com | alice |
137 # +-------------------+-------------+------------+
138 # | bob@example.com | example.com | bob |
139 # +-------------------+-------------+------------+
140 # | adam@example.net | example.net | adam |
141 # +-------------------+-------------+------------+
142 # | beth@example.net | example.net | beth |
143 # +-------------------+-------------+------------+
144 # | carol@example.net | example.net | carol |
145 # +-------------------+-------------+------------+
148 # +-------------------------------------------------------+
150 # +-------------------+--------------------+--------------+
151 # | address | goto | domain |
152 # +-------------------+--------------------+--------------+
153 # | alice@example.com | alice@example.com, | example.com |
154 # | | adam@example.net, | |
155 # | | bob@example.com, | |
156 # | | carol@example.net | |
157 # +-------------------+--------------------+--------------+
158 # | bob@example.com | bob@example.com | example.com |
159 # +-------------------+--------------------+--------------+
160 # | adam@example.net | adam@example.net | example.net |
161 # +-------------------+--------------------+--------------+
162 # | beth@example.net | beth@example.net | example.net |
163 # +-------------------+--------------------+--------------+
164 # | carol@example.net | carol@example.net | example.net |
165 # +-------------------+--------------------+--------------+
168 # +---------------------------------+
170 # +-------------------+-------------+
171 # | username | domain |
172 # +-------------------+-------------+
173 # | admin@example.com | example.com |
174 # +-------------------+-------------+
175 # | admin@example.com | example.net |
176 # +-------------------+-------------+
181 # +---------+--------------------+
182 # | user_id | username |
183 # +---------+--------------------+
184 # | 1 | alice@example.com |
185 # +---------+--------------------+
186 # | 2 | booger@example.com |
187 # +---------+--------------------+
188 # | 3 | adam@example.net |
189 # +---------+--------------------+
191 # First make sure we get rid of everything so we don't get random
192 # failures from databases and directories that already exist.
195 cfg
= configuration()
197 # First create the "mail directories".
198 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/alice")
199 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/booger")
200 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/jeremy")
201 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.net/adam")
203 # Now the databases and their content.
204 connection
= connect_superuser()
206 cfg
.plugins
.each
do |plugin
|
207 plugin_dbname
= cfg
.send("#{plugin}_dbname")
208 next if plugin_dbname
.nil? # Skip the dovecot plugin
209 query
= "CREATE DATABASE #{plugin_dbname};"
210 connection
.sync_exec(query
)
213 :host => cfg
.send("#{plugin}_dbhost"),
214 :port => cfg
.send("#{plugin}_dbport"),
215 :options => cfg
.send("#{plugin}_dbopts"),
216 :dbname => plugin_dbname
,
217 :user => cfg
.send("#{plugin}_dbuser"),
218 :password => cfg
.send("#{plugin}_dbpass")
221 plugin_conn
= PG
::Connection.new(plugin_dbhash
)
223 sql
= File
.open("test/sql/#{plugin}.sql").read()
224 plugin_conn
.sync_exec(sql
)
225 sql
= File
.open("test/sql/#{plugin}-fixtures.sql").read()
226 plugin_conn
.sync_exec(sql
)
235 # Drop all of the databases that were created in setup().
236 cfg
= configuration()
237 connection
= connect_superuser()
239 # Don't emit notices about missing tables. Why this happens when I
240 # explicitly say IF EXISTS is beyond me.
241 connection
.set_notice_processor
{}
243 cfg
.plugins
.each
do |plugin
|
244 plugin_dbname
= cfg
.send("#{plugin}_dbname")
245 next if plugin_dbname
.nil? # Skip the dovecot plugin
246 query
= "DROP DATABASE IF EXISTS #{plugin_dbname};"
247 connection
.sync_exec(query
)
252 # Get rid of the maildirs.
253 FileUtils
.rm_rf(cfg
.dovecot_mail_root())