test: show id:<> works even if the first duplicate is deleted
[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 test_begin_subtest 'First subject preserved'
9 cat <<EOF > EXPECTED
10 thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; message 1 (inbox unread)
11 EOF
12 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
13 test_expect_equal_file EXPECTED OUTPUT
14
15 test_begin_subtest 'Search for second subject'
16 cat <<EOF >EXPECTED
17 MAIL_DIR/copy1
18 MAIL_DIR/copy2
19 EOF
20 notmuch search --output=files subject:'"message 2"' | notmuch_dir_sanitize > OUTPUT
21 test_expect_equal_file EXPECTED OUTPUT
22
23 add_message '[id]="duplicate"' '[body]="sekrit" [filename]=copy3'
24 test_begin_subtest 'search for body in duplicate file'
25 cat <<EOF >EXPECTED
26 MAIL_DIR/copy1
27 MAIL_DIR/copy2
28 MAIL_DIR/copy3
29 EOF
30 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
31 test_expect_equal_file EXPECTED OUTPUT
32
33 rm ${MAIL_DIR}/copy3
34 test_begin_subtest 'reindex drops terms in duplicate file'
35 cp /dev/null EXPECTED
36 notmuch reindex '*'
37 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
38 test_expect_equal_file EXPECTED OUTPUT
39
40 rm ${MAIL_DIR}/copy1
41 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working'
42 test_subtest_known_broken
43 output=$(notmuch show --body=false --format=json id:duplicate)
44 expected='[[[{
45     "id": "'duplicate'",
46     "match": true,
47     "excluded": false,
48     "filename": [
49         "'"${MAIL_DIR}"/copy1'",
50         "'"${MAIL_DIR}"/copy2'"
51     ],
52     "timestamp": 978709435,
53     "date_relative": "2001-01-05",
54     "tags": ["inbox","unread"],
55     "headers": {
56         "Subject": "message 2",
57         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
58         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
59         "Date": "Fri, 05 Jan 2001 15:43:55 +0000"
60     }
61  },
62 []]]]'
63
64 test_expect_equal_json "$output" "$expected"
65
66 test_done