]> git.cworth.org Git - notmuch-old/blob - test/T530-upgrade.sh
test: error handling in _n_message_{add,remove}_filename
[notmuch-old] / test / T530-upgrade.sh
1 #!/usr/bin/env bash
2 test_description='database upgrades'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 test_require_external_prereq xapian-metadata
6
7 XAPIAN_PATH=$MAIL_DIR/.notmuch/xapian
8 BACKUP_PATH=$MAIL_DIR/.notmuch/backups
9
10 delete_feature () {
11     local key=$1
12     features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^$key")
13     xapian-metadata set $XAPIAN_PATH features "$features"
14 }
15
16 add_email_corpus
17
18 for key in 'multiple paths per message' \
19                'relative directory paths' \
20                'exact folder:/path: search' \
21                'mail documents for missing messages' \
22                'modification tracking'; do
23     backup_database
24     test_begin_subtest "upgrade is triggered by missing '$key'"
25     delete_feature "$key"
26     output=$(notmuch new | grep Welcome)
27     test_expect_equal \
28         "$output" \
29         "Welcome to a new version of notmuch! Your database will now be upgraded."
30
31     restore_database
32
33     backup_database
34     test_begin_subtest "backup can be restored ['$key']"
35     notmuch dump > BEFORE
36     delete_feature "$key"
37     notmuch new
38     notmuch tag -inbox '*'
39     dump_file=$(echo ${BACKUP_PATH}/dump*)
40     notmuch restore --input=$dump_file
41     notmuch dump > AFTER
42     test_expect_equal_file BEFORE AFTER
43     restore_database
44 done
45
46 for key in 'from/subject/message-ID in database' \
47                'indexed MIME types' \
48                'index body and headers separately'; do
49     backup_database
50     test_begin_subtest "upgrade not triggered by missing '$key'"
51     delete_feature "$key"
52     output=$(notmuch new | grep Welcome)
53     test_expect_equal "$output" ""
54     restore_database
55 done
56
57 test_begin_subtest "upgrade with configured backup dir"
58 notmuch config set database.backup_dir ${HOME}/backups
59 delete_feature 'modification tracking'
60 notmuch new | grep Backing | notmuch_dir_sanitize | sed 's/dump-[0-9T]*/dump-XXX/' > OUTPUT
61 cat <<EOF > EXPECTED
62 Backing up tags to CWD/home/backups/dump-XXX.gz...
63 EOF
64 test_expect_equal_file EXPECTED OUTPUT
65
66 test_begin_subtest "upgrade with relative configured backup dir"
67 notmuch config set database.backup_dir ${HOME}/backups
68 delete_feature 'modification tracking'
69 notmuch new | grep Backing | notmuch_dir_sanitize | sed 's/dump-[0-9T]*/dump-XXX/' > OUTPUT
70 cat <<EOF > EXPECTED
71 Backing up tags to CWD/home/backups/dump-XXX.gz...
72 EOF
73 test_expect_equal_file EXPECTED OUTPUT
74
75
76 test_done