]> git.notmuchmail.org Git - notmuch/blob - test/T055-path-config.sh
2045a55568da7f7b5e9d5cc3c120e4113df7662e
[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     cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
20 }
21
22 split_config () {
23     local dir
24     backup_config
25     dir="$TMP_DIRECTORY/database.$test_count"
26     rm -rf $dir
27     mkdir $dir
28     notmuch config set database.path $dir
29     notmuch config set database.mail_root $MAIL_DIR
30     DATABASE_PATH=$dir
31     XAPIAN_PATH="$dir/xapian"
32 }
33
34 symlink_config () {
35     local dir
36     backup_config
37     dir="$TMP_DIRECTORY/link.$test_count"
38     ln -s $MAIL_DIR $dir
39     notmuch config set database.path $dir
40     notmuch config set database.mail_root $MAIL_DIR
41     XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
42     unset DATABASE_PATH
43 }
44
45 xdg_config () {
46     local dir
47     local profile=${1:-default}
48
49     if [[ $profile != default ]]; then
50         export NOTMUCH_PROFILE=$profile
51     fi
52
53     backup_config
54     DATABASE_PATH="${HOME}/.local/share/notmuch/${profile}"
55     rm -rf $DATABASE_PATH
56     mkdir -p $DATABASE_PATH
57
58     config_dir="${HOME}/.config/notmuch/${profile}"
59     mkdir -p ${config_dir}
60     CONFIG_PATH=$config_dir/config
61     mv ${NOTMUCH_CONFIG} $CONFIG_PATH
62     unset NOTMUCH_CONFIG
63
64     XAPIAN_PATH="${DATABASE_PATH}/xapian"
65     notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
66     notmuch --config=${CONFIG_PATH} config set database.path
67 }
68
69 for config in traditional split XDG XDG+profile symlink; do
70     #start each set of tests with an known set of messages
71     add_email_corpus
72
73     case $config in
74         traditional)
75             backup_config
76             XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
77             ;;
78         split)
79             split_config
80             mv mail/.notmuch/xapian $DATABASE_PATH
81             ;;
82         XDG)
83             xdg_config
84             mv mail/.notmuch/xapian $DATABASE_PATH
85             ;;
86         XDG+profile)
87             xdg_config ${RANDOM}
88             mv mail/.notmuch/xapian $DATABASE_PATH
89             ;;
90         symlink)
91             symlink_config
92             ;;
93     esac
94
95     test_begin_subtest "count ($config)"
96     output=$(notmuch count '*')
97     test_expect_equal "$output" '52'
98
99     test_begin_subtest "count+tag ($config)"
100     tag="tag${RANDOM}"
101     notmuch tag +$tag '*'
102     output=$(notmuch count tag:$tag)
103     notmuch tag -$tag '*'
104     test_expect_equal "$output" '52'
105
106     test_begin_subtest "address ($config)"
107     notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
108     cat <<EOF >EXPECTED
109 Carl Worth <cworth@cworth.org>
110 notmuch@notmuchmail.org
111 EOF
112     test_expect_equal_file EXPECTED OUTPUT
113
114     test_begin_subtest "dump ($config)"
115     notmuch dump is:attachment and is:signed | sort > OUTPUT
116     cat <<EOF > EXPECTED
117 #notmuch-dump batch-tag:3 config,properties,tags
118 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
119 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
120 EOF
121     test_expect_equal_file EXPECTED OUTPUT
122
123     test_begin_subtest "dump + tag + restore ($config)"
124     notmuch dump '*' > EXPECTED
125     notmuch tag -inbox '*'
126     notmuch restore < EXPECTED
127     notmuch dump > OUTPUT
128     test_expect_equal_file EXPECTED OUTPUT
129
130     test_begin_subtest "reindex ($config)"
131     notmuch search --output=messages '*' > EXPECTED
132     notmuch reindex '*'
133     notmuch search --output=messages '*' > OUTPUT
134     test_expect_equal_file EXPECTED OUTPUT
135
136     test_begin_subtest "use existing database ($config)"
137     output=$(notmuch new)
138     test_expect_equal "$output" 'No new mail.'
139
140     test_begin_subtest "create database ($config)"
141     rm -rf $DATABASE_PATH/{.notmuch,}/xapian
142     notmuch new
143     output=$(notmuch count '*')
144     test_expect_equal "$output" '52'
145
146     test_begin_subtest "detect new files ($config)"
147     generate_message
148     generate_message
149     notmuch new
150     output=$(notmuch count '*')
151     test_expect_equal "$output" '54'
152
153     test_begin_subtest "Show a raw message ($config)"
154     add_message
155     notmuch show --format=raw id:$gen_msg_id > OUTPUT
156     test_expect_equal_file $gen_msg_filename OUTPUT
157     rm -f $gen_msg_filename
158
159     test_begin_subtest "reply ($config)"
160     add_message '[from]="Sender <sender@example.com>"' \
161                 [to]=test_suite@notmuchmail.org \
162                 [subject]=notmuch-reply-test \
163                 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
164                 '[body]="basic reply test"'
165     notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
166     cat <<EOF > EXPECTED
167 From: Notmuch Test Suite <test_suite@notmuchmail.org>
168 Subject: Re: notmuch-reply-test
169 To: Sender <sender@example.com>
170 In-Reply-To: <${gen_msg_id}>
171 References: <${gen_msg_id}>
172
173 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
174 > basic reply test
175 EOF
176     test_expect_equal_file EXPECTED OUTPUT
177     test_begin_subtest "insert+search ($config)"
178     generate_message \
179         "[subject]=\"insert-subject\"" \
180         "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
181         "[body]=\"insert-message\""
182     mkdir -p "$MAIL_DIR"/{cur,new,tmp}
183     notmuch insert < "$gen_msg_filename"
184     cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
185     test_expect_equal_file "$cur_msg_filename" "$gen_msg_filename"
186
187
188     test_begin_subtest "compact+search ($config)"
189     notmuch search --output=messages '*' | sort > EXPECTED
190     notmuch compact
191     notmuch search --output=messages '*' | sort > OUTPUT
192     test_expect_equal_file EXPECTED OUTPUT
193
194     test_begin_subtest "upgrade backup ($config)"
195     features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
196     xapian-metadata set $XAPIAN_PATH features "$features"
197     output=$(notmuch new | grep Welcome)
198     test_expect_equal \
199         "$output" \
200         "Welcome to a new version of notmuch! Your database will now be upgraded."
201
202     test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
203     mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
204     notmuch > OUTPUT
205 cat <<EOF > EXPECTED
206 Notmuch is configured, but no database was found.
207 You probably want to run "notmuch new" now to create a database.
208
209 Note that the first run of "notmuch new" can take a very long time
210 and that the resulting database will use roughly the same amount of
211 storage space as the email being indexed.
212
213 EOF
214     mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"
215
216    test_expect_equal_file EXPECTED OUTPUT
217
218    test_begin_subtest "Set config value ($config)"
219    name=${RANDOM}
220    value=${RANDOM}
221    notmuch config set test${test_count}.${name} ${value}
222    output=$(notmuch config get test${test_count}.${name})
223    notmuch config set test${test_count}.${name}
224    output2=$(notmuch config get test${test_count}.${name})
225    test_expect_equal "${output}+${output2}" "${value}+"
226
227    test_begin_subtest "Set config value in database ($config)"
228    name=${RANDOM}
229    value=${RANDOM}
230    notmuch config set --database test${test_count}.${name} ${value}
231    output=$(notmuch config get test${test_count}.${name})
232    notmuch config set --database test${test_count}.${name}
233    output2=$(notmuch config get test${test_count}.${name})
234    test_expect_equal "${output}+${output2}" "${value}+"
235
236    test_begin_subtest "Config list ($config)"
237    notmuch config list | notmuch_dir_sanitize | sed -e "s/^database.backup_dir=.*$/database.backup_dir/"  \
238                                                     -e "s/^database.hook_dir=.*$/database.hook_dir/" \
239                                                     -e "s/^database.path=.*$/database.path/" > OUTPUT
240    cat <<EOF > EXPECTED
241 built_with.compact=true
242 built_with.field_processor=true
243 built_with.retry_lock=true
244 database.backup_dir
245 database.hook_dir
246 database.mail_root=MAIL_DIR
247 database.path
248 maildir.synchronize_flags=true
249 new.ignore=
250 new.tags=unread;inbox
251 search.exclude_tags=
252 user.name=Notmuch Test Suite
253 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
254 user.primary_email=test_suite@notmuchmail.org
255 EOF
256    test_expect_equal_file EXPECTED OUTPUT
257
258    case $config in
259        XDG*)
260            test_begin_subtest "Set shadowed config value in database ($config)"
261            name=${RANDOM}
262            value=${RANDOM}
263            key=test${test_count}.${name}
264            notmuch config set --database ${key}  ${value}
265            notmuch config set ${key} shadow${value}
266            output=$(notmuch --config='' config get ${key})
267            notmuch config set --database ${key}
268            output2=$(notmuch --config='' config get ${key})
269            notmuch config set ${key}
270            test_expect_equal "${output}+${output2}" "${value}+"
271            ;;
272    esac
273    restore_config
274    rm -rf home/.local
275    rm -rf home/.config
276 done
277
278 test_done