[PATCH v4 4/4] Tests for maildir synchronization
[notmuch-archives.git] / e1 / 76014a5f0ae4bf7ec336d728dfdd62cfb672f2
1 Return-Path: <wsh@resox.2x.cz>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id CDCB540D16B\r
6         for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:49:04 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=unavailable\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 055PvEuhsgn7 for <notmuch@notmuchmail.org>;\r
16         Sun, 31 Oct 2010 14:48:49 -0700 (PDT)\r
17 Received: from smtp.nextra.cz (smtp.nextra.cz [212.65.193.3])\r
18         by olra.theworths.org (Postfix) with ESMTP id 7554240D16C\r
19         for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:48:02 -0700 (PDT)\r
20 Received: from resox.2x.cz (unknown [213.29.198.144])\r
21         by smtp.nextra.cz (Postfix) with ESMTP id A3D2188D35;\r
22         Sun, 31 Oct 2010 22:30:36 +0100 (CET)\r
23 Received: from wsh by resox.2x.cz with local (Exim 4.72)\r
24         (envelope-from <wsh@resox.2x.cz>)\r
25         id 1PCfTu-0004wr-Dp; Sun, 31 Oct 2010 22:30:26 +0100\r
26 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH v4 4/4] Tests for maildir synchronization\r
29 Date: Sun, 31 Oct 2010 22:29:18 +0100\r
30 Message-Id: <1288560558-18915-5-git-send-email-sojkam1@fel.cvut.cz>\r
31 X-Mailer: git-send-email 1.7.1\r
32 In-Reply-To: <87tyk3vpxd.fsf@wsheee.2x.cz>\r
33 References: <87tyk3vpxd.fsf@wsheee.2x.cz>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sun, 31 Oct 2010 21:49:05 -0000\r
47 \r
48 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
49 ---\r
50  test/maildir-sync |  231 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
51  test/notmuch-test |    2 +-\r
52  test/test-lib.sh  |   14 +++-\r
53  3 files changed, 244 insertions(+), 3 deletions(-)\r
54  create mode 100755 test/maildir-sync\r
55 \r
56 diff --git a/test/maildir-sync b/test/maildir-sync\r
57 new file mode 100755\r
58 index 0000000..23d612e\r
59 --- /dev/null\r
60 +++ b/test/maildir-sync\r
61 @@ -0,0 +1,231 @@\r
62 +#!/bin/bash\r
63 +\r
64 +test_description="Test maildir synchronization"\r
65 +\r
66 +. ./test-lib.sh\r
67 +\r
68 +filter_show() {\r
69 +    sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'\r
70 +    echo\r
71 +}\r
72 +\r
73 +cat >> "$NOTMUCH_CONFIG" <<EOF\r
74 +[maildir]\r
75 +synchronize_flags=true\r
76 +EOF\r
77 +\r
78 +test_begin_subtest "No new messages"\r
79 +output=$(NOTMUCH_NEW)\r
80 +test_expect_equal "$output" "No new mail."\r
81 +\r
82 +cat > expected <<EOF\r
83 +Added 1 new message to the database.\r
84 +EOF\r
85 +test_expect_success "Add a message, no flags" '\r
86 +generate_message [subject]="\"test message\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-001:2,\"" &&\r
87 +NOTMUCH_NEW > actual &&\r
88 +test_cmp expected actual\r
89 +#emacs --eval "(gdb \"gdb --annotate=3 --args $(which notmuch) new\")"\r
90 +'\r
91 +cat > expected <<EOF\r
92 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)\r
93 +EOF\r
94 +test_expect_success 'Search for the message' '\r
95 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
96 +test_cmp expected actual\r
97 +'\r
98 +cat > expected <<EOF\r
99 +No new mail. Detected 1 file rename.\r
100 +EOF\r
101 +test_expect_success 'Add seen flag' '\r
102 +mv "${gen_msg_filename}" "${gen_msg_filename}S" &&\r
103 +increment_mtime "$(dirname "${gen_msg_filename}")" &&\r
104 +NOTMUCH_NEW > actual &&\r
105 +test_cmp expected actual\r
106 +'\r
107 +cat > expected <<EOF\r
108 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)\r
109 +EOF\r
110 +test_expect_success 'Check that tags were updated' '\r
111 +notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&\r
112 +test_cmp expected actual\r
113 +'\r
114 +cat > expected <<EOF\r
115 +Added 1 new message to the database.\r
116 +EOF\r
117 +test_expect_success "Add a seen message" '\r
118 +generate_message [subject]="\"test message 2\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-002:2,S\"" &&\r
119 +NOTMUCH_NEW > actual &&\r
120 +test_cmp expected actual\r
121 +'\r
122 +cat > expected <<EOF\r
123 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)\r
124 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 2 (inbox)\r
125 +EOF\r
126 +test_expect_success 'Check that the seen message is not tagged unread' '\r
127 +notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&\r
128 +test_cmp expected actual\r
129 +'\r
130 +test_expect_success 'Tag the seen messages as replied' '\r
131 +notmuch tag +replied -inbox tag:inbox and not tag:unread\r
132 +'\r
133 +\r
134 +cat > expected <<EOF\r
135 +msg-001:2,RS\r
136 +msg-002:2,RS\r
137 +EOF\r
138 +test_expect_success 'Check that R flag was added' '\r
139 +ls -1 "${MAIL_DIR}" > actual &&\r
140 +test_cmp expected actual\r
141 +'\r
142 +cat <<EOF > show-expected\r
143 +[[[{"id": "msg-001@notmuch-test-suite",\r
144 +"match": true,\r
145 +"filename": "msg-001:2,RS",\r
146 +"timestamp": 946728000,\r
147 +"date_relative": "2000-01-01",\r
148 +"headers": {"Subject": "test message",\r
149 +"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
150 +"To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
151 +"Cc": "",\r
152 +"Bcc": "",\r
153 +"Date": "Sat,\r
154 +01 Jan 2000 12:00:00 -0000"},\r
155 +"body": [{"id": 1,\r
156 +"content-type": "text/plain",\r
157 +"content": "This is just a test message (#1)\n"}]},\r
158 +[]]]]\r
159 +EOF\r
160 +\r
161 +test_expect_success 'Message renamed due to changed flags can be shown without running notmuch new' '\r
162 +notmuch show --format=json id:msg-001@notmuch-test-suite | filter_show > show-actual &&\r
163 +test_cmp show-expected show-actual\r
164 +'\r
165 +\r
166 +test_expect_success 'Test that we can reply to the renamed message' '\r
167 +notmuch reply id:msg-001@notmuch-test-suite\r
168 +'\r
169 +\r
170 +echo "No new mail." > expected\r
171 +test_expect_success 'No rename should be detected by notmuch new' '\r
172 +increment_mtime "$(dirname "${gen_msg_filename}")" &&\r
173 +notmuch new > actual &&\r
174 +test_cmp expected actual\r
175 +'\r
176 +test_expect_success "Add a message to new/ without info" '\r
177 +generate_message [subject]="\"test message 3\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=new &&\r
178 +NOTMUCH_NEW > actual &&\r
179 +test_cmp - actual <<EOF\r
180 +Added 1 new message to the database.\r
181 +EOF\r
182 +'\r
183 +test_expect_success "Check that the message has inbox and unread tags" '\r
184 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
185 +test_cmp - actual <<EOF\r
186 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox unread)\r
187 +EOF\r
188 +'\r
189 +test_expect_success "Tag the message with 'tmp' tag" '\r
190 +notmuch tag +tmp tag:inbox and tag:unread'\r
191 +\r
192 +test_expect_success "Check that the message was not moved from new/ to cur/" '\r
193 +echo filename:$gen_msg_filename > expected &&\r
194 +notmuch show id:$gen_msg_id|grep -o "filename:.*$" > actual &&\r
195 +test_cmp expected actual &&\r
196 +test -f "$gen_msg_filename"\r
197 +'\r
198 +test_expect_success "Check that the message was not renamed" '\r
199 +ls "${MAIL_DIR}/new" > actual &&\r
200 +test_cmp - actual <<EOF\r
201 +msg-003\r
202 +EOF\r
203 +'\r
204 +test_expect_success 'Removing of unread tag should fail without cur/' '\r
205 +test_must_fail notmuch tag -unread tag:inbox and tag:unread\r
206 +'\r
207 +test_expect_success "Check that the tags were not changed" '\r
208 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
209 +test_cmp - actual <<EOF\r
210 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp unread)\r
211 +EOF\r
212 +'\r
213 +\r
214 +# notmuch new is not necessary here, but we run it in order to check\r
215 +# for 'no rename' later (*).\r
216 +test_expect_success 'Create cur/ and let notmuch know about it' '\r
217 +mkdir "$MAIL_DIR/cur" &&\r
218 +notmuch new\r
219 +'\r
220 +test_expect_success 'Removing of unread tag should pass with cur/' '\r
221 +notmuch tag -unread tag:inbox and tag:unread\r
222 +'\r
223 +test_expect_success 'Check that the message was moved to cur/' '\\r
224 +ls "$MAIL_DIR/cur" > actual &&\r
225 +test_cmp - actual <<EOF\r
226 +msg-003:2,S\r
227 +EOF\r
228 +'\r
229 +test_expect_success 'No rename should be detected by notmuch new' '\r
230 +increment_mtime "$MAIL_DIR/cur" &&\r
231 +notmuch new > actual &&\r
232 +test_cmp - actual <<EOF\r
233 +No new mail.\r
234 +EOF\r
235 +'\r
236 +# (*) If notmuch new was not run we've got "Processed 1 file in almost\r
237 +# no time" here. The reason is that removing unread tag in a previous\r
238 +# test created directory document in the database but this document\r
239 +# was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new\r
240 +# could not reach the cur/ directory and its files in it during\r
241 +# recurive traversal.\r
242 +test_expect_success 'Remove info from file name' '\r
243 +mv "$MAIL_DIR/cur/msg-003:2,S" "$MAIL_DIR/cur/msg-003" &&\r
244 +increment_mtime "$MAIL_DIR/cur" &&\r
245 +NOTMUCH_NEW > actual\r
246 +test_cmp - actual <<EOF\r
247 +No new mail. Detected 1 file rename.\r
248 +EOF\r
249 +'\r
250 +test_expect_success "Check that removing info did not change tags" '\r
251 +notmuch search tag:inbox | notmuch_search_sanitize > actual &&\r
252 +test_cmp - actual <<EOF\r
253 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp)\r
254 +EOF\r
255 +'\r
256 +test_expect_success "Add a message to fakenew/ without info" '\r
257 +generate_message [subject]="\"test message 4\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=fakenew &&\r
258 +NOTMUCH_NEW > actual &&\r
259 +test_cmp - actual <<EOF\r
260 +Added 1 new message to the database.\r
261 +EOF\r
262 +'\r
263 +test_expect_success "Check that the message has inbox and unread tags" '\r
264 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
265 +test_cmp - actual <<EOF\r
266 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 4 (inbox unread)\r
267 +EOF\r
268 +'\r
269 +test_expect_success 'Removing of unread tag should leave the message in fakenew/' '\r
270 +notmuch tag -unread tag:inbox and tag:unread &&\r
271 +ls "$MAIL_DIR/fakenew" > actual &&\r
272 +test_cmp - actual <<EOF\r
273 +msg-004:2,S\r
274 +EOF\r
275 +'\r
276 +\r
277 +test_expect_success 'Make maildir flags out of sync with the database' '\r
278 +ls $MAIL_DIR > expected &&\r
279 +mv $MAIL_DIR/msg-001:2,RS $MAIL_DIR/msg-001:2, &&\r
280 +mv $MAIL_DIR/msg-002:2,RS $MAIL_DIR/msg-002:2, &&\r
281 +increment_mtime $MAIL_DIR\r
282 +'\r
283 +\r
284 +test_expect_success 'Test whether dump/new/restore synchronizes the maildir flags with the database' '\r
285 +notmuch dump dump.txt &&\r
286 +notmuch new &&\r
287 +notmuch restore dump.txt &&\r
288 +ls $MAIL_DIR > actual &&\r
289 +test_cmp expected actual\r
290 +'\r
291 +\r
292 +test_done\r
293 diff --git a/test/notmuch-test b/test/notmuch-test\r
294 index 60c3ecb..3691f0d 100755\r
295 --- a/test/notmuch-test\r
296 +++ b/test/notmuch-test\r
297 @@ -16,7 +16,7 @@ fi\r
298  \r
299  cd $(dirname "$0")\r
300  \r
301 -TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs"\r
302 +TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs maildir-sync"\r
303  \r
304  # Clean up any results from a previous run\r
305  rm -r test-results >/dev/null 2>/dev/null\r
306 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
307 index 8f39aa7..43a1314 100644\r
308 --- a/test/test-lib.sh\r
309 +++ b/test/test-lib.sh\r
310 @@ -245,6 +245,12 @@ increment_mtime ()\r
311  #      Generate the message in directory 'directory/of/choice' within\r
312  #      the mail store. The directory will be created if necessary.\r
313  #\r
314 +#  [filename]=name\r
315 +#\r
316 +#      Store the message in file 'name'. The default is to store it\r
317 +#      in 'msg-<count>', where <count> is three-digit number of the\r
318 +#      message.\r
319 +#      \r
320  #  [body]=text\r
321  #\r
322  #      Text to use as the body of the email message\r
323 @@ -281,10 +287,14 @@ generate_message ()\r
324      local additional_headers\r
325  \r
326      gen_msg_cnt=$((gen_msg_cnt + 1))\r
327 -    gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)\r
328 +    if [ -z "${template[filename]}" ]; then\r
329 +       gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"\r
330 +    else\r
331 +       gen_msg_name=${template[filename]}\r
332 +    fi\r
333  \r
334      if [ -z "${template[id]}" ]; then\r
335 -       gen_msg_id="${gen_msg_name}@notmuch-test-suite"\r
336 +       gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"\r
337      else\r
338         gen_msg_id="${template[id]}"\r
339      fi\r
340 -- \r
341 1.7.1\r
342 \r