test/duplicate-mid: clarify index order vs filename order
[notmuch.git] / test / T670-duplicate-mid.sh
1 #!/usr/bin/env bash
2 test_description="duplicate message ids"
3 . ./test-lib.sh || exit 1
4
5 add_message '[id]="duplicate"' '[subject]="message 1" [filename]=copy1'
6 add_message '[id]="duplicate"' '[subject]="message 2" [filename]=copy2'
7
8 add_message '[id]="duplicate"' '[subject]="message 0" [filename]=copy0'
9 test_begin_subtest 'search: first indexed subject preserved'
10 cat <<EOF > EXPECTED
11 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 1 (inbox unread)
12 EOF
13 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
14 test_expect_equal_file EXPECTED OUTPUT
15
16 test_begin_subtest 'Search for second subject'
17 cat <<EOF >EXPECTED
18 MAIL_DIR/copy0
19 MAIL_DIR/copy1
20 MAIL_DIR/copy2
21 EOF
22 notmuch search --output=files subject:'"message 2"' | notmuch_dir_sanitize > OUTPUT
23 test_expect_equal_file EXPECTED OUTPUT
24
25 add_message '[id]="duplicate"' '[body]="sekrit" [filename]=copy3'
26 test_begin_subtest 'search for body in duplicate file'
27 cat <<EOF >EXPECTED
28 MAIL_DIR/copy0
29 MAIL_DIR/copy1
30 MAIL_DIR/copy2
31 MAIL_DIR/copy3
32 EOF
33 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
34 test_expect_equal_file EXPECTED OUTPUT
35
36 rm ${MAIL_DIR}/copy3
37 test_begin_subtest 'reindex drops terms in duplicate file'
38 cp /dev/null EXPECTED
39 notmuch reindex '*'
40 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
41 test_expect_equal_file EXPECTED OUTPUT
42
43 rm ${MAIL_DIR}/copy0
44 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working'
45 output=$(notmuch show --body=false --format=json id:duplicate |
46              notmuch_json_show_sanitize | sed 's/message [0-9]/A_SUBJECT/')
47 expected='[[[{
48     "id": "XXXXX",
49     "match": true,
50     "excluded": false,
51     "filename": [
52         "'"${MAIL_DIR}"/copy0'",
53         "'"${MAIL_DIR}"/copy1'",
54         "'"${MAIL_DIR}"/copy2'"
55     ],
56     "timestamp": 42,
57     "date_relative": "2001-01-05",
58     "tags": ["inbox","unread"],
59     "headers": {
60         "Subject": "A_SUBJECT",
61         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
62         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
63         "Date": "GENERATED_DATE"
64     }
65  },
66 []]]]'
67
68 test_expect_equal_json "$output" "$expected"
69
70 test_done