]> git.notmuchmail.org Git - notmuch/blob - test/T055-path-config.sh
lib/open: support XDG_DATA_HOME as a fallback database location.
[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 backup_config () {
6     local test_name=$(basename $0 .sh)
7     cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
8 }
9
10 restore_config () {
11     local test_name=$(basename $0 .sh)
12     export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
13     unset CONFIG_PATH
14     unset DATABASE_PATH
15     unset NOTMUCH_PROFILE
16     cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
17 }
18
19 split_config () {
20     local dir
21     backup_config
22     dir="$TMP_DIRECTORY/database.$test_count"
23     rm -rf $dir
24     mkdir $dir
25     notmuch config set database.path $dir
26     notmuch config set database.mail_root $MAIL_DIR
27     DATABASE_PATH=$dir
28 }
29
30 symlink_config () {
31     local dir
32     backup_config
33     dir="$TMP_DIRECTORY/link.$test_count"
34     ln -s $MAIL_DIR $dir
35     notmuch config set database.path $dir
36     notmuch config set database.mail_root $MAIL_DIR
37     unset DATABASE_PATH
38 }
39
40 xdg_config () {
41     local dir
42     local profile=${1:-default}
43
44     if [[ $profile != default ]]; then
45         export NOTMUCH_PROFILE=$profile
46     fi
47
48     backup_config
49     DATABASE_PATH="${HOME}/.local/share/notmuch/${profile}"
50     rm -rf $DATABASE_PATH
51     mkdir -p $DATABASE_PATH
52
53     config_dir="${HOME}/.config/notmuch/${profile}"
54     mkdir -p ${config_dir}
55     CONFIG_PATH=$config_dir/config
56     mv ${NOTMUCH_CONFIG} $CONFIG_PATH
57     unset NOTMUCH_CONFIG
58
59     notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
60     notmuch --config=${CONFIG_PATH} config set database.path
61 }
62
63 for config in traditional split XDG XDG+profile symlink; do
64     #start each set of tests with an known set of messages
65     add_email_corpus
66
67     case $config in
68         traditional)
69             backup_config
70             ;;
71         split)
72             split_config
73             mv mail/.notmuch/xapian $DATABASE_PATH
74             ;;
75         XDG)
76             xdg_config
77             mv mail/.notmuch/xapian $DATABASE_PATH
78             ;;
79         XDG+profile)
80             xdg_config ${RANDOM}
81             mv mail/.notmuch/xapian $DATABASE_PATH
82             ;;
83         symlink)
84             symlink_config
85             ;;
86     esac
87
88     test_begin_subtest "count ($config)"
89     output=$(notmuch count '*')
90     test_expect_equal "$output" '52'
91
92     test_begin_subtest "count+tag ($config)"
93     tag="tag${RANDOM}"
94     notmuch tag +$tag '*'
95     output=$(notmuch count tag:$tag)
96     notmuch tag -$tag '*'
97     test_expect_equal "$output" '52'
98
99     test_begin_subtest "address ($config)"
100     notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
101     cat <<EOF >EXPECTED
102 Carl Worth <cworth@cworth.org>
103 notmuch@notmuchmail.org
104 EOF
105     test_expect_equal_file EXPECTED OUTPUT
106
107     test_begin_subtest "dump ($config)"
108     notmuch dump is:attachment and is:signed | sort > OUTPUT
109     cat <<EOF > EXPECTED
110 #notmuch-dump batch-tag:3 config,properties,tags
111 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
112 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
113 EOF
114     test_expect_equal_file EXPECTED OUTPUT
115
116     test_begin_subtest "dump + tag + restore ($config)"
117     notmuch dump '*' > EXPECTED
118     notmuch tag -inbox '*'
119     notmuch restore < EXPECTED
120     notmuch dump > OUTPUT
121     test_expect_equal_file EXPECTED OUTPUT
122
123     test_begin_subtest "reindex ($config)"
124     notmuch search --output=messages '*' > EXPECTED
125     notmuch reindex '*'
126     notmuch search --output=messages '*' > OUTPUT
127     test_expect_equal_file EXPECTED OUTPUT
128
129     test_begin_subtest "use existing database ($config)"
130     output=$(notmuch new)
131     test_expect_equal "$output" 'No new mail.'
132
133     test_begin_subtest "create database ($config)"
134     rm -rf $DATABASE_PATH/{.notmuch,}/xapian
135     notmuch new
136     output=$(notmuch count '*')
137     test_expect_equal "$output" '52'
138
139     test_begin_subtest "detect new files ($config)"
140     generate_message
141     generate_message
142     notmuch new
143     output=$(notmuch count '*')
144     test_expect_equal "$output" '54'
145
146     test_begin_subtest "Show a raw message ($config)"
147     add_message
148     notmuch show --format=raw id:$gen_msg_id > OUTPUT
149     test_expect_equal_file $gen_msg_filename OUTPUT
150     rm -f $gen_msg_filename
151
152     test_begin_subtest "reply ($config)"
153     add_message '[from]="Sender <sender@example.com>"' \
154                 [to]=test_suite@notmuchmail.org \
155                 [subject]=notmuch-reply-test \
156                 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
157                 '[body]="basic reply test"'
158     notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
159     cat <<EOF > EXPECTED
160 From: Notmuch Test Suite <test_suite@notmuchmail.org>
161 Subject: Re: notmuch-reply-test
162 To: Sender <sender@example.com>
163 In-Reply-To: <${gen_msg_id}>
164 References: <${gen_msg_id}>
165
166 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
167 > basic reply test
168 EOF
169     test_expect_equal_file EXPECTED OUTPUT
170     restore_config
171 done
172
173 test_done