]>
gitweb.michael.orlitzky.com - mailshears.git/blob - mailshears_test.rb
483c587a08d0a7682de79def66096ccfe50d4dac
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 mail_root
= cfg
.send('mail_root')
21 return File
.directory
?("#{mail_root}/#{dir}")
24 def connect_superuser()
25 # Connect to the database (specified in the test configuration) as
26 # the superuser. Your local configuration is expected to be such
27 # that this "just works."
36 connection
= PGconn
.connect(db_host
,
48 # Connect to the database specified in the test configutation as
49 # the super user. Then, run all of the SQL scripts contained in
50 # test/sql. These scripts create the tables for the plugins listed
51 # in the test configuration, and then create some sample data.
53 # Here is the full list of what gets created. Every test case
54 # inheriting from this class can expect this schema and data to
55 # exist. The filesystem entries are located beneath mail_root from
56 # the configuration file.
61 # * example.com/booger
62 # * example.com/jeremy
69 # +----------------------------+
71 # +------------------+---------+
72 # | username | options |
73 # +------------------+---------+
74 # | adam@example.net | herp |
75 # +------------------+---------+
78 # +------------------------------------------------------+
80 # +-----+------------------+----------+------------------+
81 # | sid | user_from | calendar | user_which |
82 # +-----+------------------+----------+------------------+
83 # | 1 | adam@example.net | derp | beth@example.net |
84 # +-----+------------------+----------+------------------+
89 # +-------------------------------------------------------+
91 # +---------+--------+----------------+-------------------+
92 # | user_no | active | joined | username |
93 # +---------+--------+----------------+-------------------+
94 # | 17 | t | 2014-01-04 ... | alice@example.com |
95 # +---------+--------+----------------+-------------------+
98 # +-----------------------------------------+
100 # +---------+--------------+----------------+
101 # | user_no | setting_name | setting_value |
102 # +---------+--------------+----------------+
103 # | 17 | dumb setting | its dumb value |
104 # +---------+--------------+----------------+
107 # 3. postfixadmin_test
122 # +----------------------------------------------+
124 # +-------------------+-------------+------------+
125 # | username | domain | local_part |
126 # +-------------------+-------------+------------+
127 # | alice@example.com | example.com | alice |
128 # +-------------------+-------------+------------+
129 # | bob@example.com | example.com | bob |
130 # +-------------------+-------------+------------+
131 # | adam@example.net | example.net | adam |
132 # +-------------------+-------------+------------+
133 # | beth@example.net | example.net | beth |
134 # +-------------------+-------------+------------+
135 # | carol@example.net | example.net | carol |
136 # +-------------------+-------------+------------+
139 # +------------------------------------------------------+
141 # +-------------------+-------------------+--------------+
142 # | address | goto | domain |
143 # +-------------------+-------------------+--------------+
144 # | alice@example.com | alice@example.com | example.com |
145 # +-------------------+-------------------+--------------+
146 # | bob@example.com | bob@example.com | example.com |
147 # +-------------------+-------------------+--------------+
148 # | adam@example.net | adam@example.net | example.net |
149 # +-------------------+-------------------+--------------+
150 # | beth@example.net | beth@example.net | example.net |
151 # +-------------------+-------------------+--------------+
152 # | carol@example.net | carol@example.net | example.net |
153 # +-------------------+-------------------+--------------+
156 # +---------------------------------+
158 # +-------------------+-------------+
159 # | username | domain |
160 # +-------------------+-------------+
161 # | admin@example.com | example.com |
162 # +-------------------+-------------+
163 # | admin@example.com | example.net |
164 # +-------------------+-------------+
169 # +---------+-------------------+
170 # | user_id | username |
171 # +---------+-------------------+
172 # | 1 | alice@example.com |
173 # +---------+-------------------+
174 # | 2 | adam@example.net |
175 # +---------+-------------------+
177 cfg
= configuration()
179 # First create the "mail directories".
180 mail_root
= cfg
.send('mail_root')
181 FileUtils
.mkdir_p("#{mail_root}/example.com/alice")
182 FileUtils
.mkdir_p("#{mail_root}/example.com/booger")
183 FileUtils
.mkdir_p("#{mail_root}/example.com/jeremy")
184 FileUtils
.mkdir_p("#{mail_root}/example.net/adam")
186 # Now the databases and their content.
187 connection
= connect_superuser()
189 cfg
.plugins
.each
do |plugin
|
190 plugin_dbname
= cfg
.send("#{plugin}_dbname")
191 next if plugin_dbname
.nil? # Skip the dovecot plugin
192 query
= "CREATE DATABASE #{plugin_dbname};"
193 connection
.query(query
)
195 plugin_dbhost
= cfg
.send("#{plugin}_dbhost")
196 plugin_dbport
= cfg
.send("#{plugin}_dbport")
197 plugin_dbopts
= cfg
.send("#{plugin}_dbopts")
198 plugin_dbtty
= cfg
.send("#{plugin}_dbtty")
199 plugin_dbuser
= cfg
.send("#{plugin}_dbuser")
200 plugin_dbpass
= cfg
.send("#{plugin}_dbpass")
202 plugin_conn
= PGconn
.connect(plugin_dbhost
,
210 sql
= File
.open("test/sql/#{plugin}.sql").read()
211 plugin_conn
.query(sql
)
212 sql
= File
.open("test/sql/#{plugin}-fixtures.sql").read()
213 plugin_conn
.query(sql
)
222 # Drop all of the databases that were created in setup().
223 cfg
= configuration()
224 connection
= connect_superuser()
226 cfg
.plugins
.each
do |plugin
|
227 plugin_dbname
= cfg
.send("#{plugin}_dbname")
228 next if plugin_dbname
.nil? # Skip the dovecot plugin
229 query
= "DROP DATABASE #{plugin_dbname};"
230 connection
.query(query
)
235 # Get rid of the maildirs.
236 mail_root
= cfg
.send('mail_root')
237 FileUtils
.rm_r(mail_root
)