]>
gitweb.michael.orlitzky.com - mailshears.git/blob - test/mailshears_test.rb
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 # +--------------------+---------+
75 # | booger@example.com | herp |
76 # +------------------ +---------+
79 # +---------------------------------------------------------+
81 # +-----+--------------------+----------+-------------------+
82 # | sid | user_from | calendar | user_which |
83 # +-----+--------------------+----------+-------------------+
84 # | 1 | adam@example.net | derp | beth@example.net |
85 # +-----+--------------------+----------+-------------------+
86 # | 2 | booger@example.com | derp | carol@example.net |
87 # +-----+--------------------+----------+-------------------+
92 # +--------------------------------------------------------+
94 # +---------+--------+----------------+--------------------+
95 # | user_no | active | joined | username |
96 # +---------+--------+----------------+--------------------+
97 # | 17 | t | 2014-01-04 ... | alice@example.com |
98 # +---------+--------+----------------+--------------------+
99 # | 18 | t | 2014-01-04 ... | booger@example.com |
100 # +---------+--------+----------------+--------------------+
103 # +-----------------------------------------+
105 # +---------+--------------+----------------+
106 # | user_no | setting_name | setting_value |
107 # +---------+--------------+----------------+
108 # | 17 | dumb setting | its dumb value |
109 # +---------+--------------+----------------+
110 # | 18 | dumb setting | its dumb value |
111 # +---------+--------------+----------------+
114 # 3. postfixadmin_test
129 # +----------------------------------------------+
131 # +-------------------+-------------+------------+
132 # | username | domain | local_part |
133 # +-------------------+-------------+------------+
134 # | alice@example.com | example.com | alice |
135 # +-------------------+-------------+------------+
136 # | bob@example.com | example.com | bob |
137 # +-------------------+-------------+------------+
138 # | adam@example.net | example.net | adam |
139 # +-------------------+-------------+------------+
140 # | beth@example.net | example.net | beth |
141 # +-------------------+-------------+------------+
142 # | carol@example.net | example.net | carol |
143 # +-------------------+-------------+------------+
146 # +------------------------------------------------------+
148 # +-------------------+-------------------+--------------+
149 # | address | goto | domain |
150 # +-------------------+-------------------+--------------+
151 # | alice@example.com | alice@example.com | example.com |
152 # +-------------------+-------------------+--------------+
153 # | bob@example.com | bob@example.com | example.com |
154 # +-------------------+-------------------+--------------+
155 # | adam@example.net | adam@example.net | example.net |
156 # +-------------------+-------------------+--------------+
157 # | beth@example.net | beth@example.net | example.net |
158 # +-------------------+-------------------+--------------+
159 # | carol@example.net | carol@example.net | example.net |
160 # +-------------------+-------------------+--------------+
163 # +---------------------------------+
165 # +-------------------+-------------+
166 # | username | domain |
167 # +-------------------+-------------+
168 # | admin@example.com | example.com |
169 # +-------------------+-------------+
170 # | admin@example.com | example.net |
171 # +-------------------+-------------+
176 # +---------+--------------------+
177 # | user_id | username |
178 # +---------+--------------------+
179 # | 1 | alice@example.com |
180 # +---------+--------------------+
181 # | 2 | booger@example.com |
182 # +---------+--------------------+
183 # | 3 | adam@example.net |
184 # +---------+--------------------+
186 cfg
= configuration()
188 # First create the "mail directories".
189 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/alice")
190 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/booger")
191 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.com/jeremy")
192 FileUtils
.mkdir_p("#{cfg.dovecot_mail_root()}/example.net/adam")
194 # Now the databases and their content.
195 connection
= connect_superuser()
197 cfg
.plugins
.each
do |plugin
|
198 plugin_dbname
= cfg
.send("#{plugin}_dbname")
199 next if plugin_dbname
.nil? # Skip the dovecot plugin
200 query
= "CREATE DATABASE #{plugin_dbname};"
201 connection
.query(query
)
203 plugin_dbhost
= cfg
.send("#{plugin}_dbhost")
204 plugin_dbport
= cfg
.send("#{plugin}_dbport")
205 plugin_dbopts
= cfg
.send("#{plugin}_dbopts")
206 plugin_dbtty
= cfg
.send("#{plugin}_dbtty")
207 plugin_dbuser
= cfg
.send("#{plugin}_dbuser")
208 plugin_dbpass
= cfg
.send("#{plugin}_dbpass")
210 plugin_conn
= PGconn
.connect(plugin_dbhost
,
218 sql
= File
.open("test/sql/#{plugin}.sql").read()
219 plugin_conn
.query(sql
)
220 sql
= File
.open("test/sql/#{plugin}-fixtures.sql").read()
221 plugin_conn
.query(sql
)
230 # Drop all of the databases that were created in setup().
231 cfg
= configuration()
232 connection
= connect_superuser()
234 cfg
.plugins
.each
do |plugin
|
235 plugin_dbname
= cfg
.send("#{plugin}_dbname")
236 next if plugin_dbname
.nil? # Skip the dovecot plugin
237 query
= "DROP DATABASE #{plugin_dbname};"
238 connection
.query(query
)
243 # Get rid of the maildirs.
244 FileUtils
.rm_r(cfg
.dovecot_mail_root())