c4c4ac8b64475955b91d07ca188102d3d626c82b
[notmuch] / test / T530-upgrade.sh
1 #!/usr/bin/env bash
2 test_description="database upgrade"
3
4 . ./test-lib.sh
5
6 dbtarball=database-v1.tar.xz
7
8 # XXX: Accomplish the same with test lib helpers
9 if [ ! -e ${TEST_DIRECTORY}/test-databases/${dbtarball} ]; then
10     test_subtest_missing_external_prereq_["${dbtarball} - fetch with 'make download-test-databases'"]=t
11 fi
12
13 test_expect_success \
14     'database checksum' \
15     '( cd $TEST_DIRECTORY/test-databases &&
16        sha256sum --quiet --check --status ${dbtarball}.sha256 )'
17
18 tar xf $TEST_DIRECTORY/test-databases/${dbtarball} -C ${MAIL_DIR} --strip-components=1
19
20 test_begin_subtest "folder: search does not work with old database version"
21 output=$(notmuch search folder:foo)
22 test_expect_equal "$output" ""
23
24 test_begin_subtest "path: search does not work with old database version"
25 output=$(notmuch search path:foo)
26 test_expect_equal "$output" ""
27
28 test_expect_success 'pre upgrade dump' 'notmuch dump | sort > pre-upgrade-dump'
29
30 test_begin_subtest "database upgrade from format version 1"
31 output=$(notmuch new | sed -e 's/^Backing up tags to .*$/Backing up tags to FILENAME/')
32 test_expect_equal "$output" "\
33 Welcome to a new version of notmuch! Your database will now be upgraded.
34 This process is safe to interrupt.
35 Backing up tags to FILENAME
36 Your notmuch database has now been upgraded.
37 No new mail."
38
39 test_begin_subtest "tag backup matches pre-upgrade dump"
40 gunzip -c ${MAIL_DIR}/.notmuch/dump-*.gz | sort > backup-dump
41 test_expect_equal_file pre-upgrade-dump backup-dump
42
43 test_begin_subtest "folder: no longer matches in the middle of path"
44 output=$(notmuch search folder:baz)
45 test_expect_equal "$output" ""
46
47 test_begin_subtest "folder: search"
48 output=$(notmuch search --output=files folder:foo | notmuch_search_files_sanitize | sort)
49 test_expect_equal "$output" "MAIL_DIR/foo/06:2,
50 MAIL_DIR/foo/cur/07:2,
51 MAIL_DIR/foo/cur/08:2,
52 MAIL_DIR/foo/new/03:2,
53 MAIL_DIR/foo/new/09:2,
54 MAIL_DIR/foo/new/10:2,"
55
56 test_begin_subtest "top level folder: search"
57 output=$(notmuch search --output=files folder:'""' | notmuch_search_files_sanitize | sort)
58 # bar/18:2, is a duplicate of cur/51:2,
59 test_expect_equal "$output" "MAIL_DIR/01:2,
60 MAIL_DIR/02:2,
61 MAIL_DIR/bar/18:2,
62 MAIL_DIR/cur/29:2,
63 MAIL_DIR/cur/30:2,
64 MAIL_DIR/cur/31:2,
65 MAIL_DIR/cur/32:2,
66 MAIL_DIR/cur/33:2,
67 MAIL_DIR/cur/34:2,
68 MAIL_DIR/cur/35:2,
69 MAIL_DIR/cur/36:2,
70 MAIL_DIR/cur/37:2,
71 MAIL_DIR/cur/38:2,
72 MAIL_DIR/cur/39:2,
73 MAIL_DIR/cur/40:2,
74 MAIL_DIR/cur/41:2,
75 MAIL_DIR/cur/42:2,
76 MAIL_DIR/cur/43:2,
77 MAIL_DIR/cur/44:2,
78 MAIL_DIR/cur/45:2,
79 MAIL_DIR/cur/46:2,
80 MAIL_DIR/cur/47:2,
81 MAIL_DIR/cur/48:2,
82 MAIL_DIR/cur/49:2,
83 MAIL_DIR/cur/50:2,
84 MAIL_DIR/cur/51:2,
85 MAIL_DIR/cur/52:2,
86 MAIL_DIR/cur/53:2,
87 MAIL_DIR/new/04:2,"
88
89 test_begin_subtest "path: search"
90 output=$(notmuch search --output=files path:"bar" | notmuch_search_files_sanitize | sort)
91 # cur/51:2, is a duplicate of bar/18:2,
92 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
93 MAIL_DIR/bar/18:2,
94 MAIL_DIR/cur/51:2,"
95
96 test_begin_subtest "top level path: search"
97 output=$(notmuch search --output=files path:'""' | notmuch_search_files_sanitize | sort)
98 test_expect_equal "$output" "MAIL_DIR/01:2,
99 MAIL_DIR/02:2,"
100
101 test_begin_subtest "recursive path: search"
102 output=$(notmuch search --output=files path:"bar/**" | notmuch_search_files_sanitize | sort)
103 # cur/51:2, is a duplicate of bar/18:2,
104 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
105 MAIL_DIR/bar/18:2,
106 MAIL_DIR/bar/baz/05:2,
107 MAIL_DIR/bar/baz/23:2,
108 MAIL_DIR/bar/baz/24:2,
109 MAIL_DIR/bar/baz/cur/25:2,
110 MAIL_DIR/bar/baz/cur/26:2,
111 MAIL_DIR/bar/baz/new/27:2,
112 MAIL_DIR/bar/baz/new/28:2,
113 MAIL_DIR/bar/cur/19:2,
114 MAIL_DIR/bar/cur/20:2,
115 MAIL_DIR/bar/new/21:2,
116 MAIL_DIR/bar/new/22:2,
117 MAIL_DIR/cur/51:2,"
118
119 test_done