]> git.cworth.org Git - notmuch-old/blob - test/T700-reindex.sh
CLI/git: add safety checks for checkout and commit
[notmuch-old] / test / T700-reindex.sh
1 #!/usr/bin/env bash
2 test_description='reindexing messages'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus
6
7
8 if [ $NOTMUCH_HAVE_SFSEXP -eq 1 ]; then
9
10     count=$(notmuch count --lastmod '*' | cut -f 3)
11     for query in '()' '(not)' '(and)' '(or ())' '(or (not))' '(or (and))' \
12                 '(or (and) (or) (not (and)))'; do
13         test_begin_subtest "reindex all messages: $query"
14         notmuch reindex --query=sexp "$query"
15         output=$(notmuch count --lastmod '*' | cut -f 3)
16         count=$((count + 1))
17         test_expect_equal "$output" "$count"
18     done
19
20 fi
21
22 notmuch tag +usertag1 '*'
23
24 notmuch search '*' 2>1 | notmuch_search_sanitize > initial-threads
25 notmuch search --output=messages '*' 2>/dev/null > initial-message-ids
26 notmuch dump > initial-dump
27
28 test_begin_subtest 'reindex preserves threads'
29 notmuch reindex '*'
30 notmuch search '*' | notmuch_search_sanitize > OUTPUT
31 test_expect_equal_file initial-threads OUTPUT
32
33 test_begin_subtest 'reindex after removing duplicate file preserves threads'
34 # remove one copy
35 sed 's,3/3(4),3/3,' < initial-threads > EXPECTED
36 mv $MAIL_DIR/bar/18:2, duplicate-msg-1.eml
37 notmuch reindex '*'
38 notmuch search '*' | notmuch_search_sanitize > OUTPUT
39 test_expect_equal_file EXPECTED OUTPUT
40
41 test_begin_subtest 'reindex preserves message-ids'
42 notmuch reindex '*'
43 notmuch search --output=messages '*' > OUTPUT
44 test_expect_equal_file initial-message-ids OUTPUT
45
46 test_begin_subtest 'reindex preserves tags'
47 notmuch reindex '*'
48 notmuch dump > OUTPUT
49 test_expect_equal_file initial-dump OUTPUT
50
51 test_begin_subtest 'reindex preserves tags with special prefixes'
52 notmuch tag +attachment2 +encrypted2 +signed2 '*'
53 notmuch dump > EXPECTED
54 notmuch reindex '*'
55 notmuch dump > OUTPUT
56 notmuch tag -attachment2 -encrypted2 -signed2 '*'
57 test_expect_equal_file EXPECTED OUTPUT
58
59 backup_database
60 test_begin_subtest 'reindex moves a message between threads'
61 notmuch search --output=threads id:87iqd9rn3l.fsf@vertex.dottedmag > EXPECTED
62 # re-parent
63 sed -i 's/1258471718-6781-1-git-send-email-dottedmag@dottedmag.net/87iqd9rn3l.fsf@vertex.dottedmag/' $MAIL_DIR/02:2,*
64 notmuch reindex id:1258471718-6781-2-git-send-email-dottedmag@dottedmag.net
65 notmuch search --output=threads id:1258471718-6781-2-git-send-email-dottedmag@dottedmag.net > OUTPUT
66 test_expect_equal_file EXPECTED OUTPUT
67 restore_database
68
69 backup_database
70 test_begin_subtest 'reindex detects removal of all files'
71 notmuch search --output=messages not id:20091117232137.GA7669@griffis1.net> EXPECTED
72 # remove both copies
73 mv $MAIL_DIR/cur/51:2,* duplicate-message-2.eml
74 notmuch reindex id:20091117232137.GA7669@griffis1.net
75 notmuch search --output=messages '*' > OUTPUT
76 test_expect_equal_file EXPECTED OUTPUT
77 restore_database
78
79 backup_database
80 test_begin_subtest 'reindex detects removal of all files'
81 notmuch search --output=messages not id:20091117232137.GA7669@griffis1.net> EXPECTED
82 # remove both copies
83 mv $MAIL_DIR/cur/51:2,* duplicate-message-2.eml
84 notmuch reindex id:20091117232137.GA7669@griffis1.net
85 notmuch search --output=messages '*' > OUTPUT
86 test_expect_equal_file EXPECTED OUTPUT
87 restore_database
88
89 test_begin_subtest "reindex preserves properties"
90 cat <<EOF > prop-dump
91 #= 1258471718-6781-1-git-send-email-dottedmag@dottedmag.net userprop=userval
92 #= 1258471718-6781-2-git-send-email-dottedmag@dottedmag.net userprop=userval
93 #= 1258491078-29658-1-git-send-email-dottedmag@dottedmag.net userprop=userval1
94 #= 20091117190054.GU3165@dottiness.seas.harvard.edu userprop=userval
95 #= 20091117203301.GV3165@dottiness.seas.harvard.edu userprop=userval3
96 #= 87fx8can9z.fsf@vertex.dottedmag userprop=userval2
97 #= 87iqd9rn3l.fsf@vertex.dottedmag userprop=userval
98 #= 87lji4lx9v.fsf@yoom.home.cworth.org userprop=userval3
99 #= 87lji5cbwo.fsf@yoom.home.cworth.org userprop=userval
100 #= cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com userprop=userval
101 EOF
102 notmuch restore < prop-dump
103 notmuch reindex '*'
104 notmuch dump | grep '^#=' | sort > OUTPUT
105 test_expect_equal_file prop-dump OUTPUT
106
107 add_email_corpus lkml
108
109 test_begin_subtest "reindex of lkml corpus preserves threads"
110 notmuch search '*' | notmuch_search_sanitize > EXPECTED
111 notmuch reindex '*'
112 notmuch search '*' | notmuch_search_sanitize > OUTPUT
113 test_expect_equal_file EXPECTED OUTPUT
114
115
116 test_begin_subtest "reindex after removing corpus"
117 tar cf backup.tar mail/cur
118 find mail/cur -type f -delete
119 test_expect_success "notmuch reindex '*'"
120 tar xf backup.tar
121
122 test_done