]> git.cworth.org Git - notmuch-old/blob - test/T055-path-config.sh
test: error handling in _n_message_{add,remove}_filename
[notmuch-old] / test / T055-path-config.sh
1 #!/usr/bin/env bash
2 test_description='Configuration of mail-root and database path'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 test_require_external_prereq xapian-metdata
6
7 backup_config () {
8     local test_name=$(basename $0 .sh)
9     cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
10 }
11
12 restore_config () {
13     local test_name=$(basename $0 .sh)
14     export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
15     unset CONFIG_PATH
16     unset DATABASE_PATH
17     unset NOTMUCH_PROFILE
18     unset XAPIAN_PATH
19     unset MAILDIR
20     rm -f "$HOME/mail"
21     cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
22 }
23
24 split_config () {
25     local dir
26     backup_config
27     dir="$TMP_DIRECTORY/database.$test_count"
28     rm -rf $dir
29     mkdir $dir
30     notmuch config set database.path $dir
31     notmuch config set database.mail_root $MAIL_DIR
32     DATABASE_PATH=$dir
33     XAPIAN_PATH="$dir/xapian"
34 }
35
36 symlink_config () {
37     local dir
38     backup_config
39     dir="$TMP_DIRECTORY/link.$test_count"
40     ln -s $MAIL_DIR $dir
41     notmuch config set database.path $dir
42     notmuch config set database.mail_root $MAIL_DIR
43     XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
44     unset DATABASE_PATH
45 }
46
47
48 home_mail_config () {
49     local dir
50     backup_config
51     dir="${HOME}/mail"
52     ln -s $MAIL_DIR $dir
53     notmuch config set database.path
54     notmuch config set database.mail_root
55     XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
56     unset DATABASE_PATH
57 }
58
59 maildir_env_config () {
60     local dir
61     backup_config
62     dir="${HOME}/env_points_here"
63     ln -s $MAIL_DIR $dir
64     export MAILDIR=$dir
65     notmuch config set database.path
66     notmuch config set database.mail_root
67     XAPIAN_PATH="${MAIL_DIR}/.notmuch/xapian"
68     unset DATABASE_PATH
69 }
70
71 xdg_config () {
72     local dir
73     local profile=${1:-default}
74
75     if [[ $profile != default ]]; then
76         export NOTMUCH_PROFILE=$profile
77     fi
78
79     backup_config
80     DATABASE_PATH="${HOME}/.local/share/notmuch/${profile}"
81     rm -rf $DATABASE_PATH
82     mkdir -p $DATABASE_PATH
83
84     config_dir="${HOME}/.config/notmuch/${profile}"
85     mkdir -p ${config_dir}
86     CONFIG_PATH=$config_dir/config
87     mv ${NOTMUCH_CONFIG} $CONFIG_PATH
88     unset NOTMUCH_CONFIG
89
90     XAPIAN_PATH="${DATABASE_PATH}/xapian"
91     notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
92     notmuch --config=${CONFIG_PATH} config set database.path
93 }
94
95 for config in traditional split XDG XDG+profile symlink home_mail maildir_env; do
96     #start each set of tests with an known set of messages
97     add_email_corpus
98
99     case $config in
100         traditional)
101             backup_config
102             XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
103             ;;
104         split)
105             split_config
106             mv mail/.notmuch/xapian $DATABASE_PATH
107             ;;
108         XDG)
109             xdg_config
110             mv mail/.notmuch/xapian $DATABASE_PATH
111             ;;
112         XDG+profile)
113             xdg_config ${RANDOM}
114             mv mail/.notmuch/xapian $DATABASE_PATH
115             ;;
116         symlink)
117             symlink_config
118             ;;
119         home_mail)
120             home_mail_config
121             ;;
122         maildir_env)
123             maildir_env_config
124             ;;
125     esac
126
127     test_begin_subtest "count ($config)"
128     output=$(notmuch count '*')
129     test_expect_equal "$output" '52'
130
131     test_begin_subtest "count+tag ($config)"
132     tag="tag${RANDOM}"
133     notmuch tag +$tag '*'
134     output=$(notmuch count tag:$tag)
135     notmuch tag -$tag '*'
136     test_expect_equal "$output" '52'
137
138     test_begin_subtest "address ($config)"
139     notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
140     cat <<EOF >EXPECTED
141 Carl Worth <cworth@cworth.org>
142 notmuch@notmuchmail.org
143 EOF
144     test_expect_equal_file EXPECTED OUTPUT
145
146     test_begin_subtest "dump ($config)"
147     notmuch dump is:attachment and is:signed | sort > OUTPUT
148     cat <<EOF > EXPECTED
149 #notmuch-dump batch-tag:3 config,properties,tags
150 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
151 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
152 EOF
153     test_expect_equal_file EXPECTED OUTPUT
154
155     test_begin_subtest "dump + tag + restore ($config)"
156     notmuch dump '*' > EXPECTED
157     notmuch tag -inbox '*'
158     notmuch restore < EXPECTED
159     notmuch dump > OUTPUT
160     test_expect_equal_file_nonempty EXPECTED OUTPUT
161
162     test_begin_subtest "reindex ($config)"
163     notmuch search --output=messages '*' > EXPECTED
164     notmuch reindex '*'
165     notmuch search --output=messages '*' > OUTPUT
166     test_expect_equal_file_nonempty EXPECTED OUTPUT
167
168     test_begin_subtest "use existing database ($config)"
169     output=$(notmuch new)
170     test_expect_equal "$output" 'No new mail.'
171
172     test_begin_subtest "create database ($config)"
173     rm -rf $DATABASE_PATH/{.notmuch,}/xapian
174     notmuch new
175     output=$(notmuch count '*')
176     test_expect_equal "$output" '52'
177
178     test_begin_subtest "detect new files ($config)"
179     generate_message
180     generate_message
181     notmuch new
182     output=$(notmuch count '*')
183     test_expect_equal "$output" '54'
184
185     test_begin_subtest "Show a raw message ($config)"
186     add_message
187     notmuch show --format=raw id:$gen_msg_id > OUTPUT
188     test_expect_equal_file_nonempty $gen_msg_filename OUTPUT
189     rm -f $gen_msg_filename
190
191     test_begin_subtest "reply ($config)"
192     add_message '[from]="Sender <sender@example.com>"' \
193                 [to]=test_suite@notmuchmail.org \
194                 [subject]=notmuch-reply-test \
195                 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
196                 '[body]="basic reply test"'
197     notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
198     cat <<EOF > EXPECTED
199 From: Notmuch Test Suite <test_suite@notmuchmail.org>
200 Subject: Re: notmuch-reply-test
201 To: Sender <sender@example.com>
202 In-Reply-To: <${gen_msg_id}>
203 References: <${gen_msg_id}>
204
205 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
206 > basic reply test
207 EOF
208     test_expect_equal_file EXPECTED OUTPUT
209
210     test_begin_subtest "insert+search ($config)"
211     generate_message \
212         "[subject]=\"insert-subject\"" \
213         "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
214         "[body]=\"insert-message\""
215     mkdir -p "$MAIL_DIR"/{cur,new,tmp}
216     notmuch insert < "$gen_msg_filename"
217     cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
218     test_expect_equal_file_nonempty "$cur_msg_filename" "$gen_msg_filename"
219
220     test_begin_subtest "compact+search ($config)"
221     notmuch search --output=messages '*' | sort > EXPECTED
222     notmuch compact
223     notmuch search --output=messages '*' | sort > OUTPUT
224     test_expect_equal_file_nonempty EXPECTED OUTPUT
225
226     test_begin_subtest "upgrade backup ($config)"
227     features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
228     xapian-metadata set $XAPIAN_PATH features "$features"
229     output=$(notmuch new | grep Welcome)
230     test_expect_equal \
231         "$output" \
232         "Welcome to a new version of notmuch! Your database will now be upgraded."
233
234     test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
235     mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
236     notmuch > OUTPUT
237 cat <<EOF > EXPECTED
238 Notmuch is configured, but no database was found.
239 You probably want to run "notmuch new" now to create a database.
240
241 Note that the first run of "notmuch new" can take a very long time
242 and that the resulting database will use roughly the same amount of
243 storage space as the email being indexed.
244
245 EOF
246     mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"
247
248    test_expect_equal_file EXPECTED OUTPUT
249
250    test_begin_subtest "Set config value ($config)"
251    name=${RANDOM}
252    value=${RANDOM}
253    notmuch config set test${test_count}.${name} ${value}
254    output=$(notmuch config get test${test_count}.${name})
255    notmuch config set test${test_count}.${name}
256    output2=$(notmuch config get test${test_count}.${name})
257    test_expect_equal "${output}+${output2}" "${value}+"
258
259    test_begin_subtest "Set config value in database ($config)"
260    name=${RANDOM}
261    value=${RANDOM}
262    notmuch config set --database test${test_count}.${name} ${value}
263    output=$(notmuch config get test${test_count}.${name})
264    notmuch config set --database test${test_count}.${name}
265    output2=$(notmuch config get test${test_count}.${name})
266    test_expect_equal "${output}+${output2}" "${value}+"
267
268    test_begin_subtest "Config list ($config)"
269    notmuch config list | notmuch_config_sanitize | \
270        sed -e "s/^database.backup_dir=.*$/database.backup_dir/"  \
271            -e "s/^database.hook_dir=.*$/database.hook_dir/" \
272            -e "s/^database.path=.*$/database.path/"  \
273            -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
274            -e "s,^database.mail_root=CWD/home/env_points_here,database.mail_root=MAIL_DIR," \
275            > OUTPUT
276    cat <<EOF > EXPECTED
277 built_with.compact=something
278 built_with.field_processor=something
279 built_with.retry_lock=something
280 built_with.sexp_queries=something
281 database.autocommit=8000
282 database.backup_dir
283 database.hook_dir
284 database.mail_root=MAIL_DIR
285 database.path
286 maildir.synchronize_flags=true
287 new.ignore=
288 new.tags=unread;inbox
289 search.exclude_tags=
290 user.name=Notmuch Test Suite
291 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
292 user.primary_email=test_suite@notmuchmail.org
293 EOF
294    test_expect_equal_file EXPECTED OUTPUT
295
296    test_begin_subtest "Config list from python ($config)"
297    test_python <<EOF > OUTPUT
298 from notmuch2 import Database
299 db=Database(config=Database.CONFIG.SEARCH)
300 for key in list(db.config):
301     print(key)
302 EOF
303    cat <<EOF > EXPECTED
304 database.autocommit
305 database.backup_dir
306 database.hook_dir
307 database.mail_root
308 database.path
309 maildir.synchronize_flags
310 new.tags
311 user.name
312 user.other_email
313 user.primary_email
314 EOF
315    test_expect_equal_file EXPECTED OUTPUT
316    case $config in
317        XDG*)
318            test_begin_subtest "Set shadowed config value in database ($config)"
319            name=${RANDOM}
320            value=${RANDOM}
321            key=test${test_count}.${name}
322            notmuch config set --database ${key}  ${value}
323            notmuch config set ${key} shadow${value}
324            output=$(notmuch --config='' config get ${key})
325            notmuch config set --database ${key}
326            output2=$(notmuch --config='' config get ${key})
327            notmuch config set ${key}
328            test_expect_equal "${output}+${output2}" "${value}+"
329            ;&
330        split)
331            test_begin_subtest "'to' header does not crash (python-cffi) ($config)"
332            echo 'notmuch@notmuchmail.org' > EXPECTED
333            test_python <<EOF
334 from notmuch2 import Database
335 db=Database(config=Database.CONFIG.SEARCH)
336 m=db.find('20091117232137.GA7669@griffis1.net')
337 to=m.header('To')
338 print(to)
339 EOF
340            test_expect_equal_file EXPECTED OUTPUT
341            ;;
342        *)
343            backup_database
344            test_begin_subtest ".notmuch without xapian/ handled gracefully ($config)"
345            rm -r $XAPIAN_PATH
346            test_expect_success "notmuch new"
347            restore_database
348            ;;
349    esac
350
351    case $config in
352        split|XDG*)
353    esac
354    restore_config
355    rm -rf home/.local
356    rm -rf home/.config
357 done
358
359 test_done