]> git.cworth.org Git - notmuch/blob - test/T035-read-config.sh
1e740eba35342c96116526b78c1479484d5ec097
[notmuch] / test / T035-read-config.sh
1 #!/usr/bin/env bash
2 test_description='Various options for reading configuration'
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 xdg_config () {
11     local dir
12     local profile=${1:-default}
13     if [[ $profile != default ]]; then
14         export NOTMUCH_PROFILE=$profile
15     fi
16     backup_config
17     dir="${HOME}/.config/notmuch/${profile}"
18     rm -rf $dir
19     mkdir -p $dir
20     CONFIG_PATH=$dir/config
21     mv ${NOTMUCH_CONFIG} ${CONFIG_PATH}
22     unset NOTMUCH_CONFIG
23 }
24
25 restore_config () {
26     local test_name=$(basename $0 .sh)
27     export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
28     unset CONFIG_PATH
29     unset NOTMUCH_PROFILE
30     cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
31 }
32
33 add_email_corpus
34
35 test_begin_subtest "count with saved query from config file"
36 backup_config
37 query_name="test${RANDOM}"
38 notmuch count query:$query_name > OUTPUT
39 printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
40 notmuch count query:$query_name >> OUTPUT
41 cat <<EOF > EXPECTED
42 0
43 52
44 EOF
45 restore_config
46 test_expect_equal_file EXPECTED OUTPUT
47
48 test_begin_subtest "count with saved query from config file (xdg)"
49 query_name="test${RANDOM}"
50 xdg_config
51 notmuch count query:$query_name > OUTPUT
52 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
53 notmuch count query:$query_name >> OUTPUT
54 cat <<EOF > EXPECTED
55 0
56 52
57 EOF
58 restore_config
59 test_expect_equal_file EXPECTED OUTPUT
60
61 test_begin_subtest "count with saved query from config file (xdg+profile)"
62 query_name="test${RANDOM}"
63 xdg_config work
64 notmuch count query:$query_name > OUTPUT
65 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
66 notmuch count query:$query_name >> OUTPUT
67 cat <<EOF > EXPECTED
68 0
69 52
70 EOF
71 restore_config
72 test_expect_equal_file EXPECTED OUTPUT
73
74 cat <<EOF > EXPECTED
75 Before:
76 #notmuch-dump batch-tag:3 tags
77
78 After:
79 #notmuch-dump batch-tag:3 tags
80 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
81 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
82 +inbox +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
83 +inbox +signed +unread -- id:20091117203301.GV3165@dottiness.seas.harvard.edu
84 +inbox +signed +unread -- id:20091118002059.067214ed@hikari
85 +inbox +signed +unread -- id:20091118005040.GA25380@dottiness.seas.harvard.edu
86 +inbox +signed +unread -- id:87iqd9rn3l.fsf@vertex.dottedmag
87 EOF
88
89 test_begin_subtest "dump with saved query from config file"
90 backup_config
91 query_name="test${RANDOM}"
92 CONFIG_PATH=notmuch-config
93 printf "Before:\n" > OUTPUT
94 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
95 printf "\nAfter:\n" >> OUTPUT
96 printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
97 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
98 restore_config
99 test_expect_equal_file EXPECTED OUTPUT
100
101 test_begin_subtest "dump with saved query from config file (xdg)"
102 backup_config
103 query_name="test${RANDOM}"
104 xdg_config
105 printf "Before:\n" > OUTPUT
106 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
107 printf "\nAfter:\n" >> OUTPUT
108 printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
109 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
110 restore_config
111 test_expect_equal_file EXPECTED OUTPUT
112
113 test_begin_subtest "dump with saved query from config file (xdg+profile)"
114 backup_config
115 query_name="test${RANDOM}"
116 xdg_config work
117 printf "Before:\n" > OUTPUT
118 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
119 printf "\nAfter:\n" >> OUTPUT
120 printf "\n[query]\n${query_name} = tag:signed\n" >> ${CONFIG_PATH}
121 notmuch dump --include=tags query:$query_name | sort >> OUTPUT
122 restore_config
123 test_expect_equal_file EXPECTED OUTPUT
124
125 test_begin_subtest "restore with xdg config"
126 backup_config
127 notmuch dump '*' > EXPECTED
128 notmuch tag -inbox '*'
129 xdg_config
130 notmuch restore --input=EXPECTED
131 notmuch dump > OUTPUT
132 restore_config
133 test_expect_equal_file EXPECTED OUTPUT
134
135 test_begin_subtest "restore with xdg+profile config"
136 backup_config
137 notmuch dump '*' > EXPECTED
138 notmuch tag -inbox '*'
139 xdg_config work
140 notmuch restore --input=EXPECTED
141 notmuch dump > OUTPUT
142 restore_config
143 test_expect_equal_file EXPECTED OUTPUT
144
145 test_begin_subtest "Insert message with custom new.tags (xdg)"
146 backup_config
147 xdg_config
148 tag=test${RANDOM}
149 notmuch --config=${CONFIG_PATH} config set new.tags $tag
150 generate_message \
151     "[subject]=\"insert-subject\"" \
152     "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
153     "[body]=\"insert-message\""
154 mkdir -p ${MAIL_DIR}/{cur,new,tmp}
155 notmuch insert < "$gen_msg_filename"
156 notmuch dump id:$gen_msg_id > OUTPUT
157 cat <<EOF > EXPECTED
158 #notmuch-dump batch-tag:3 config,properties,tags
159 +$tag -- id:$gen_msg_id
160 EOF
161 restore_config
162 test_expect_equal_file EXPECTED OUTPUT
163
164 test_begin_subtest "Insert message with custom new.tags (xdg+profile)"
165 backup_config
166 tag=test${RANDOM}
167 xdg_config $tag
168 notmuch --config=${CONFIG_PATH} config set new.tags $tag
169 generate_message \
170     "[subject]=\"insert-subject\"" \
171     "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
172     "[body]=\"insert-message\""
173 mkdir -p ${MAIL_DIR}/{cur,new,tmp}
174 notmuch insert < "$gen_msg_filename"
175 notmuch dump id:$gen_msg_id > OUTPUT
176 cat <<EOF > EXPECTED
177 #notmuch-dump batch-tag:3 config,properties,tags
178 +$tag -- id:$gen_msg_id
179 EOF
180 restore_config
181 test_expect_equal_file EXPECTED OUTPUT
182
183 test_begin_subtest "reindex with saved query from config file"
184 backup_config
185 query_name="test${RANDOM}"
186 count1=$(notmuch count --lastmod '*' | cut -f3)
187 printf "\n[query]\n${query_name} = tag:inbox\n" >> notmuch-config
188 notmuch reindex query:$query_name
189 count2=$(notmuch count --lastmod '*' | cut -f3)
190 restore_config
191 test_expect_success "test '$count2 -gt $count1'"
192
193 test_begin_subtest "reindex with saved query from config file (xdg)"
194 query_name="test${RANDOM}"
195 count1=$(notmuch count --lastmod '*' | cut -f3)
196 xdg_config
197 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
198 notmuch reindex query:$query_name
199 count2=$(notmuch count --lastmod '*' | cut -f3)
200 restore_config
201 test_expect_success "test '$count2 -gt $count1'"
202
203 test_begin_subtest "reindex with saved query from config file (xdg+profile)"
204 query_name="test${RANDOM}"
205 count1=$(notmuch count --lastmod '*' | cut -f3)
206 xdg_config $query_name
207 printf "\n[query]\n${query_name} = tag:inbox\n" >> ${CONFIG_PATH}
208 notmuch reindex query:$query_name
209 count2=$(notmuch count --lastmod '*' | cut -f3)
210 restore_config
211 test_expect_success "test '$count2 -gt $count1'"
212
213 test_done