]> git.notmuchmail.org Git - notmuch/blob - test/T055-path-config.sh
test: add known broken tests for finding database via MAILDIR
[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 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     [[ "$config" = maildir_env ]] && test_subtest_known_broken
129     output=$(notmuch count '*')
130     test_expect_equal "$output" '52'
131
132     test_begin_subtest "count+tag ($config)"
133     [[ "$config" = maildir_env ]] && test_subtest_known_broken
134     tag="tag${RANDOM}"
135     notmuch tag +$tag '*'
136     output=$(notmuch count tag:$tag)
137     notmuch tag -$tag '*'
138     test_expect_equal "$output" '52'
139
140     test_begin_subtest "address ($config)"
141     [[ "$config" = maildir_env ]] && test_subtest_known_broken
142     notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
143     cat <<EOF >EXPECTED
144 Carl Worth <cworth@cworth.org>
145 notmuch@notmuchmail.org
146 EOF
147     test_expect_equal_file EXPECTED OUTPUT
148
149     test_begin_subtest "dump ($config)"
150     [[ "$config" = maildir_env ]] && test_subtest_known_broken
151     notmuch dump is:attachment and is:signed | sort > OUTPUT
152     cat <<EOF > EXPECTED
153 #notmuch-dump batch-tag:3 config,properties,tags
154 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
155 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
156 EOF
157     test_expect_equal_file EXPECTED OUTPUT
158
159     test_begin_subtest "dump + tag + restore ($config)"
160     notmuch dump '*' > EXPECTED
161     notmuch tag -inbox '*'
162     notmuch restore < EXPECTED
163     notmuch dump > OUTPUT
164     test_expect_equal_file EXPECTED OUTPUT
165
166     test_begin_subtest "reindex ($config)"
167     notmuch search --output=messages '*' > EXPECTED
168     notmuch reindex '*'
169     notmuch search --output=messages '*' > OUTPUT
170     test_expect_equal_file EXPECTED OUTPUT
171
172     test_begin_subtest "use existing database ($config)"
173     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
174     output=$(notmuch new)
175     test_expect_equal "$output" 'No new mail.'
176
177     test_begin_subtest "create database ($config)"
178     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
179     rm -rf $DATABASE_PATH/{.notmuch,}/xapian
180     notmuch new
181     output=$(notmuch count '*')
182     test_expect_equal "$output" '52'
183
184     test_begin_subtest "detect new files ($config)"
185     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
186     generate_message
187     generate_message
188     notmuch new
189     output=$(notmuch count '*')
190     test_expect_equal "$output" '54'
191
192     test_begin_subtest "Show a raw message ($config)"
193     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
194     add_message
195     notmuch show --format=raw id:$gen_msg_id > OUTPUT
196     test_expect_equal_file $gen_msg_filename OUTPUT
197     rm -f $gen_msg_filename
198
199     test_begin_subtest "reply ($config)"
200     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
201     add_message '[from]="Sender <sender@example.com>"' \
202                 [to]=test_suite@notmuchmail.org \
203                 [subject]=notmuch-reply-test \
204                 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
205                 '[body]="basic reply test"'
206     notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
207     cat <<EOF > EXPECTED
208 From: Notmuch Test Suite <test_suite@notmuchmail.org>
209 Subject: Re: notmuch-reply-test
210 To: Sender <sender@example.com>
211 In-Reply-To: <${gen_msg_id}>
212 References: <${gen_msg_id}>
213
214 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
215 > basic reply test
216 EOF
217     test_expect_equal_file EXPECTED OUTPUT
218
219     test_begin_subtest "insert+search ($config)"
220     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
221     generate_message \
222         "[subject]=\"insert-subject\"" \
223         "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
224         "[body]=\"insert-message\""
225     mkdir -p "$MAIL_DIR"/{cur,new,tmp}
226     notmuch insert < "$gen_msg_filename"
227     cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
228     test_expect_equal_file "$cur_msg_filename" "$gen_msg_filename"
229
230
231     test_begin_subtest "compact+search ($config)"
232     notmuch search --output=messages '*' | sort > EXPECTED
233     notmuch compact
234     notmuch search --output=messages '*' | sort > OUTPUT
235     test_expect_equal_file EXPECTED OUTPUT
236
237     test_begin_subtest "upgrade backup ($config)"
238     [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
239     features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
240     xapian-metadata set $XAPIAN_PATH features "$features"
241     output=$(notmuch new | grep Welcome)
242     test_expect_equal \
243         "$output" \
244         "Welcome to a new version of notmuch! Your database will now be upgraded."
245
246     test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
247     mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
248     notmuch > OUTPUT
249 cat <<EOF > EXPECTED
250 Notmuch is configured, but no database was found.
251 You probably want to run "notmuch new" now to create a database.
252
253 Note that the first run of "notmuch new" can take a very long time
254 and that the resulting database will use roughly the same amount of
255 storage space as the email being indexed.
256
257 EOF
258     mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"
259
260    test_expect_equal_file EXPECTED OUTPUT
261
262    test_begin_subtest "Set config value ($config)"
263    name=${RANDOM}
264    value=${RANDOM}
265    notmuch config set test${test_count}.${name} ${value}
266    output=$(notmuch config get test${test_count}.${name})
267    notmuch config set test${test_count}.${name}
268    output2=$(notmuch config get test${test_count}.${name})
269    test_expect_equal "${output}+${output2}" "${value}+"
270
271    test_begin_subtest "Set config value in database ($config)"
272    [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
273    name=${RANDOM}
274    value=${RANDOM}
275    notmuch config set --database test${test_count}.${name} ${value}
276    output=$(notmuch config get test${test_count}.${name})
277    notmuch config set --database test${test_count}.${name}
278    output2=$(notmuch config get test${test_count}.${name})
279    test_expect_equal "${output}+${output2}" "${value}+"
280
281    test_begin_subtest "Config list ($config)"
282    [[ "$config" = "maildir_env" ]] && test_subtest_known_broken
283    notmuch config list | notmuch_dir_sanitize | \
284        sed -e "s/^database.backup_dir=.*$/database.backup_dir/"  \
285            -e "s/^database.hook_dir=.*$/database.hook_dir/" \
286            -e "s/^database.path=.*$/database.path/"  \
287            -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
288            -e "s,^database.mail_root=CWD/home/env_points_here,database.mail_root=MAIL_DIR," \
289            > OUTPUT
290    cat <<EOF > EXPECTED
291 built_with.compact=true
292 built_with.field_processor=true
293 built_with.retry_lock=true
294 database.backup_dir
295 database.hook_dir
296 database.mail_root=MAIL_DIR
297 database.path
298 maildir.synchronize_flags=true
299 new.ignore=
300 new.tags=unread;inbox
301 search.exclude_tags=
302 user.name=Notmuch Test Suite
303 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
304 user.primary_email=test_suite@notmuchmail.org
305 EOF
306    test_expect_equal_file EXPECTED OUTPUT
307
308    case $config in
309        XDG*)
310            test_begin_subtest "Set shadowed config value in database ($config)"
311            name=${RANDOM}
312            value=${RANDOM}
313            key=test${test_count}.${name}
314            notmuch config set --database ${key}  ${value}
315            notmuch config set ${key} shadow${value}
316            output=$(notmuch --config='' config get ${key})
317            notmuch config set --database ${key}
318            output2=$(notmuch --config='' config get ${key})
319            notmuch config set ${key}
320            test_expect_equal "${output}+${output2}" "${value}+"
321            ;;
322    esac
323    restore_config
324    rm -rf home/.local
325    rm -rf home/.config
326 done
327
328 test_done