]> git.notmuchmail.org Git - notmuch/blob - test/T055-path-config.sh
6df17f80f02067ef6444e40a174a78ad150dbcea
[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 for config in traditional split symlink; do
41     # start each set of tests with a known set of messages
42     add_email_corpus
43
44     case $config in
45         traditional)
46             backup_config
47             ;;
48         split)
49             split_config
50             mv mail/.notmuch/xapian $DATABASE_PATH
51             ;;
52         symlink)
53             symlink_config
54             ;;
55     esac
56
57     test_begin_subtest "count ($config)"
58     output=$(notmuch count '*')
59     test_expect_equal "$output" '52'
60
61     test_begin_subtest "count+tag ($config)"
62     tag="tag${RANDOM}"
63     notmuch tag +$tag '*'
64     output=$(notmuch count tag:$tag)
65     notmuch tag -$tag '*'
66     test_expect_equal "$output" '52'
67
68     test_begin_subtest "address ($config)"
69     notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
70     cat <<EOF >EXPECTED
71 Carl Worth <cworth@cworth.org>
72 notmuch@notmuchmail.org
73 EOF
74     test_expect_equal_file EXPECTED OUTPUT
75
76     test_begin_subtest "dump ($config)"
77     notmuch dump is:attachment and is:signed | sort > OUTPUT
78     cat <<EOF > EXPECTED
79 #notmuch-dump batch-tag:3 config,properties,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 EOF
83     test_expect_equal_file EXPECTED OUTPUT
84
85     test_begin_subtest "dump + tag + restore ($config)"
86     notmuch dump '*' > EXPECTED
87     notmuch tag -inbox '*'
88     notmuch restore < EXPECTED
89     notmuch dump > OUTPUT
90     test_expect_equal_file EXPECTED OUTPUT
91
92     test_begin_subtest "reindex ($config)"
93     notmuch search --output=messages '*' > EXPECTED
94     notmuch reindex '*'
95     notmuch search --output=messages '*' > OUTPUT
96     test_expect_equal_file EXPECTED OUTPUT
97
98     test_begin_subtest "use existing database ($config)"
99     output=$(notmuch new)
100     test_expect_equal "$output" 'No new mail.'
101
102     test_begin_subtest "create database ($config)"
103     rm -rf $DATABASE_PATH/{.notmuch,}/xapian
104     notmuch new
105     output=$(notmuch count '*')
106     test_expect_equal "$output" '52'
107
108     test_begin_subtest "detect new files ($config)"
109     generate_message
110     generate_message
111     notmuch new
112     output=$(notmuch count '*')
113     test_expect_equal "$output" '54'
114
115     test_begin_subtest "Show a raw message ($config)"
116     add_message
117     notmuch show --format=raw id:$gen_msg_id > OUTPUT
118     test_expect_equal_file $gen_msg_filename OUTPUT
119     rm -f $gen_msg_filename
120
121     test_begin_subtest "reply ($config)"
122     add_message '[from]="Sender <sender@example.com>"' \
123                 [to]=test_suite@notmuchmail.org \
124                 [subject]=notmuch-reply-test \
125                 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
126                 '[body]="basic reply test"'
127     notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
128     cat <<EOF > EXPECTED
129 From: Notmuch Test Suite <test_suite@notmuchmail.org>
130 Subject: Re: notmuch-reply-test
131 To: Sender <sender@example.com>
132 In-Reply-To: <${gen_msg_id}>
133 References: <${gen_msg_id}>
134
135 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
136 > basic reply test
137 EOF
138     test_expect_equal_file EXPECTED OUTPUT
139     restore_config
140 done
141
142 test_done