]> git.notmuchmail.org Git - notmuch/blob - test/T055-path-config.sh
test/path-config: set database.mail_root but not database.path
[notmuch] / 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 mailroot_only_config () {
96     local dir
97
98     backup_config
99     notmuch config set database.mail_root ${TMP_DIRECTORY}/mail
100     notmuch config set database.path
101     DATABASE_PATH="${HOME}/.local/share/notmuch/default"
102     rm -rf $DATABASE_PATH
103     mkdir -p $DATABASE_PATH
104     XAPIAN_PATH="${DATABASE_PATH}/xapian"
105     mv mail/.notmuch/xapian $DATABASE_PATH
106 }
107
108 for config in traditional split XDG XDG+profile symlink home_mail maildir_env mailroot_only; do
109     #start each set of tests with an known set of messages
110     add_email_corpus
111
112     case $config in
113         traditional)
114             backup_config
115             XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
116             ;;
117         split)
118             split_config
119             mv mail/.notmuch/xapian $DATABASE_PATH
120             ;;
121         XDG)
122             xdg_config
123             mv mail/.notmuch/xapian $DATABASE_PATH
124             ;;
125         XDG+profile)
126             xdg_config ${RANDOM}
127             mv mail/.notmuch/xapian $DATABASE_PATH
128             ;;
129         symlink)
130             symlink_config
131             ;;
132         home_mail)
133             home_mail_config
134             ;;
135         maildir_env)
136             maildir_env_config
137             ;;
138         mailroot_only)
139             mailroot_only_config
140             ;;
141     esac
142
143     test_begin_subtest "count ($config)"
144     output=$(notmuch count '*')
145     test_expect_equal "$output" '52'
146
147     test_begin_subtest "count+tag ($config)"
148     tag="tag${RANDOM}"
149     notmuch tag +$tag '*'
150     output=$(notmuch count tag:$tag)
151     notmuch tag -$tag '*'
152     test_expect_equal "$output" '52'
153
154     test_begin_subtest "address ($config)"
155     notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
156     cat <<EOF >EXPECTED
157 Carl Worth <cworth@cworth.org>
158 notmuch@notmuchmail.org
159 EOF
160     test_expect_equal_file EXPECTED OUTPUT
161
162     test_begin_subtest "dump ($config)"
163     notmuch dump is:attachment and is:signed | sort > OUTPUT
164     cat <<EOF > EXPECTED
165 #notmuch-dump batch-tag:3 config,properties,tags
166 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
167 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
168 EOF
169     test_expect_equal_file EXPECTED OUTPUT
170
171     test_begin_subtest "dump + tag + restore ($config)"
172     notmuch dump '*' > EXPECTED
173     notmuch tag -inbox '*'
174     notmuch restore < EXPECTED
175     notmuch dump > OUTPUT
176     test_expect_equal_file_nonempty EXPECTED OUTPUT
177
178     test_begin_subtest "reindex ($config)"
179     notmuch search --output=messages '*' > EXPECTED
180     notmuch reindex '*'
181     notmuch search --output=messages '*' > OUTPUT
182     test_expect_equal_file_nonempty EXPECTED OUTPUT
183
184     test_begin_subtest "use existing database ($config)"
185     output=$(notmuch new)
186     test_expect_equal "$output" 'No new mail.'
187
188     test_begin_subtest "create database ($config)"
189     rm -rf $DATABASE_PATH/{.notmuch,}/xapian
190     notmuch new
191     output=$(notmuch count '*')
192     test_expect_equal "$output" '52'
193
194     test_begin_subtest "detect new files ($config)"
195     generate_message
196     generate_message
197     notmuch new
198     output=$(notmuch count '*')
199     test_expect_equal "$output" '54'
200
201     test_begin_subtest "Show a raw message ($config)"
202     add_message
203     notmuch show --format=raw id:$gen_msg_id > OUTPUT
204     test_expect_equal_file_nonempty $gen_msg_filename OUTPUT
205     rm -f $gen_msg_filename
206
207     test_begin_subtest "reply ($config)"
208     add_message '[from]="Sender <sender@example.com>"' \
209                 [to]=test_suite@notmuchmail.org \
210                 [subject]=notmuch-reply-test \
211                 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
212                 '[body]="basic reply test"'
213     notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
214     cat <<EOF > EXPECTED
215 From: Notmuch Test Suite <test_suite@notmuchmail.org>
216 Subject: Re: notmuch-reply-test
217 To: Sender <sender@example.com>
218 In-Reply-To: <${gen_msg_id}>
219 References: <${gen_msg_id}>
220
221 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
222 > basic reply test
223 EOF
224     test_expect_equal_file EXPECTED OUTPUT
225
226     test_begin_subtest "insert+search ($config)"
227     generate_message \
228         "[subject]=\"insert-subject\"" \
229         "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
230         "[body]=\"insert-message\""
231     mkdir -p "$MAIL_DIR"/{cur,new,tmp}
232     notmuch insert < "$gen_msg_filename"
233     cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
234     test_expect_equal_file_nonempty "$cur_msg_filename" "$gen_msg_filename"
235
236     test_begin_subtest "compact+search ($config)"
237     notmuch search --output=messages '*' | sort > EXPECTED
238     notmuch compact
239     notmuch search --output=messages '*' | sort > OUTPUT
240     test_expect_equal_file_nonempty EXPECTED OUTPUT
241
242     test_begin_subtest "upgrade backup ($config)"
243     features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
244     xapian-metadata set $XAPIAN_PATH features "$features"
245     output=$(notmuch new | grep Welcome)
246     test_expect_equal \
247         "$output" \
248         "Welcome to a new version of notmuch! Your database will now be upgraded."
249
250     test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
251     mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
252     notmuch > OUTPUT
253 cat <<EOF > EXPECTED
254 Notmuch is configured, but no database was found.
255 You probably want to run "notmuch new" now to create a database.
256
257 Note that the first run of "notmuch new" can take a very long time
258 and that the resulting database will use roughly the same amount of
259 storage space as the email being indexed.
260
261 EOF
262     mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"
263
264    test_expect_equal_file EXPECTED OUTPUT
265
266    test_begin_subtest "Set config value ($config)"
267    name=${RANDOM}
268    value=${RANDOM}
269    notmuch config set test${test_count}.${name} ${value}
270    output=$(notmuch config get test${test_count}.${name})
271    notmuch config set test${test_count}.${name}
272    output2=$(notmuch config get test${test_count}.${name})
273    test_expect_equal "${output}+${output2}" "${value}+"
274
275    test_begin_subtest "Set config value in database ($config)"
276    name=${RANDOM}
277    value=${RANDOM}
278    notmuch config set --database test${test_count}.${name} ${value}
279    output=$(notmuch config get test${test_count}.${name})
280    notmuch config set --database test${test_count}.${name}
281    output2=$(notmuch config get test${test_count}.${name})
282    test_expect_equal "${output}+${output2}" "${value}+"
283
284    test_begin_subtest "Config list ($config)"
285    notmuch config list | notmuch_config_sanitize | \
286        sed -e "s/^database.backup_dir=.*$/database.backup_dir/"  \
287            -e "s/^database.hook_dir=.*$/database.hook_dir/" \
288            -e "s/^database.path=.*$/database.path/"  \
289            -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
290            -e "s,^database.mail_root=CWD/home/env_points_here,database.mail_root=MAIL_DIR," \
291            > OUTPUT
292    cat <<EOF > EXPECTED
293 built_with.compact=something
294 built_with.field_processor=something
295 built_with.retry_lock=something
296 built_with.sexp_queries=something
297 database.autocommit=8000
298 database.backup_dir
299 database.hook_dir
300 database.mail_root=MAIL_DIR
301 database.path
302 maildir.synchronize_flags=true
303 new.ignore=
304 new.tags=unread;inbox
305 search.exclude_tags=
306 user.name=Notmuch Test Suite
307 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
308 user.primary_email=test_suite@notmuchmail.org
309 EOF
310    test_expect_equal_file EXPECTED OUTPUT
311
312    test_begin_subtest "Config list from python ($config)"
313    test_python <<EOF > OUTPUT
314 from notmuch2 import Database
315 db=Database(config=Database.CONFIG.SEARCH)
316 for key in list(db.config):
317     print(key)
318 EOF
319    cat <<EOF > EXPECTED
320 database.autocommit
321 database.backup_dir
322 database.hook_dir
323 database.mail_root
324 database.path
325 maildir.synchronize_flags
326 new.tags
327 user.name
328 user.other_email
329 user.primary_email
330 EOF
331    test_expect_equal_file EXPECTED OUTPUT
332
333    case $config in
334        XDG*)
335            test_begin_subtest "Set shadowed config value in database ($config)"
336            name=${RANDOM}
337            value=${RANDOM}
338            key=test${test_count}.${name}
339            notmuch config set --database ${key}  ${value}
340            notmuch config set ${key} shadow${value}
341            output=$(notmuch --config='' config get ${key})
342            notmuch config set --database ${key}
343            output2=$(notmuch --config='' config get ${key})
344            notmuch config set ${key}
345            test_expect_equal "${output}+${output2}" "${value}+"
346            ;&
347        split)
348            test_begin_subtest "'to' header does not crash (python-cffi) ($config)"
349            echo 'notmuch@notmuchmail.org' > EXPECTED
350            test_python <<EOF
351 from notmuch2 import Database
352 db=Database(config=Database.CONFIG.SEARCH)
353 m=db.find('20091117232137.GA7669@griffis1.net')
354 to=m.header('To')
355 print(to)
356 EOF
357            test_expect_equal_file EXPECTED OUTPUT
358
359            test_begin_subtest ".notmuch not ignored in split config ($config)"
360            test_subtest_known_broken
361            generate_message '[dir]=.notmuch/cur' '[subject]="Do not ignore, very important"'
362            NOTMUCH_NEW > OUTPUT
363            notmuch search subject:Do-not-ignore | notmuch_search_sanitize >> OUTPUT
364            cat <<EOF > EXPECTED
365 Added 1 new message to the database.
366 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Do not ignore, very important (inbox unread)
367 EOF
368            test_expect_equal_file EXPECTED OUTPUT
369            ;&
370        mailroot_only)
371            test_begin_subtest "create database parent dir ($config)"
372            test_subtest_known_broken
373            rm -r ${DATABASE_PATH}
374            notmuch new
375            test_expect_equal "$(xapian-metadata get ${XAPIAN_PATH} version)" 3
376            ;;
377        *)
378            backup_database
379            test_begin_subtest ".notmuch without xapian/ handled gracefully ($config)"
380            rm -r $XAPIAN_PATH
381            test_expect_success "notmuch new"
382            restore_database
383            ;;
384    esac
385
386    restore_config
387    rm -rf home/.local
388    rm -rf home/.config
389 done
390
391 test_done