]> git.notmuchmail.org Git - notmuch/blob - test/T670-duplicate-mid.sh
lib: enforce that n_message_reindex takes headers from first file
[notmuch] / 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 test_begin_subtest 'reindex choses subject from first filename'
44 cat <<EOF > EXPECTED
45 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 0 (inbox unread)
46 EOF
47 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
48 test_expect_equal_file EXPECTED OUTPUT
49
50 rm ${MAIL_DIR}/copy0
51 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working'
52 output=$(notmuch show --body=false --format=json id:duplicate |
53              notmuch_json_show_sanitize | sed 's/message [0-9]/A_SUBJECT/')
54 expected='[[[{
55     "id": "XXXXX",
56     "match": true,
57     "excluded": false,
58     "filename": [
59         "'"${MAIL_DIR}"/copy0'",
60         "'"${MAIL_DIR}"/copy1'",
61         "'"${MAIL_DIR}"/copy2'"
62     ],
63     "timestamp": 42,
64     "date_relative": "2001-01-05",
65     "tags": ["inbox","unread"],
66     "headers": {
67         "Subject": "A_SUBJECT",
68         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
69         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
70         "Date": "GENERATED_DATE"
71     }
72  },
73 []]]]'
74
75 test_expect_equal_json "$output" "$expected"
76
77 test_done