]> git.notmuchmail.org Git - notmuch/blob - test/T055-path-config.sh
lib/open: check for split configuration when creating database.
[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     restore_config
99 done
100
101 test_done