]> git.notmuchmail.org Git - notmuch/blob - test/T030-config.sh
Merge tag 'debian/0.32.3-1'
[notmuch] / test / T030-config.sh
1 #!/usr/bin/env bash
2
3 test_description='"notmuch config"'
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 test_begin_subtest "Get string value"
7 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
8
9 test_begin_subtest "Get list value"
10 cat <<EOF > EXPECTED
11 inbox
12 unread
13 EOF
14 notmuch config get new.tags | sort > OUTPUT
15 test_expect_equal_file EXPECTED OUTPUT
16
17 test_begin_subtest "Set string value"
18 notmuch config set foo.string "this is a string value"
19 test_expect_equal "$(notmuch config get foo.string)" "this is a string value"
20
21 test_begin_subtest "Set string value again"
22 notmuch config set foo.string "this is another string value"
23 test_expect_equal "$(notmuch config get foo.string)" "this is another string value"
24
25 test_begin_subtest "Set list value"
26 notmuch config set foo.list this "is a" "list value"
27 test_expect_equal "$(notmuch config get foo.list)" "\
28 this
29 is a
30 list value"
31
32 test_begin_subtest "Set list value again"
33 notmuch config set foo.list this "is another" "list value"
34 test_expect_equal "$(notmuch config get foo.list)" "\
35 this
36 is another
37 list value"
38
39 test_begin_subtest "Remove key"
40 notmuch config set foo.remove baz
41 notmuch config set foo.remove
42 test_expect_equal "$(notmuch config get foo.remove)" ""
43
44 test_begin_subtest "Remove non-existent key"
45 notmuch config set foo.nonexistent
46 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
47
48 test_begin_subtest "List all items"
49 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
50 cat <<EOF > EXPECTED
51 built_with.compact=something
52 built_with.field_processor=something
53 built_with.retry_lock=something
54 database.autocommit=8000
55 database.mail_root=MAIL_DIR
56 database.path=MAIL_DIR
57 foo.list=this;is another;list value;
58 foo.string=this is another string value
59 maildir.synchronize_flags=true
60 new.ignore=
61 new.tags=unread;inbox
62 search.exclude_tags=
63 user.name=Notmuch Test Suite
64 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
65 user.primary_email=test_suite@notmuchmail.org
66 EOF
67 test_expect_equal_file EXPECTED OUTPUT
68
69 test_begin_subtest "Top level --config=FILE option"
70 cp "${NOTMUCH_CONFIG}" alt-config
71 notmuch --config=alt-config config set user.name "Another Name"
72 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
73     "Another Name"
74
75 test_begin_subtest "Top level --config:FILE option"
76 test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
77     "Another Name"
78
79 test_begin_subtest "Top level --config<space>FILE option"
80 test_expect_equal "$(notmuch --config alt-config config get user.name)" \
81     "Another Name"
82
83 test_begin_subtest "Top level --config=FILE option changed the right file"
84 test_expect_equal "$(notmuch config get user.name)" \
85     "Notmuch Test Suite"
86
87 test_begin_subtest "Read config file through a symlink"
88 ln -s alt-config alt-config-link
89 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
90     "Another Name"
91
92 test_begin_subtest "Write config file through a symlink"
93 notmuch --config=alt-config-link config set user.name "Link Name"
94 test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
95     "Link Name"
96
97 test_begin_subtest "Writing config file through symlink follows symlink"
98 test_expect_equal "$(readlink alt-config-link)" "alt-config"
99
100 test_begin_subtest "Round trip arbitrary key"
101 key=g${RANDOM}.m${RANDOM}
102 value=${RANDOM}
103 notmuch config set ${key} ${value}
104 output=$(notmuch config get ${key})
105 test_expect_equal "${output}" "${value}"
106
107 test_begin_subtest "Clear arbitrary key"
108 notmuch config set ${key}
109 output=$(notmuch config get ${key})
110 test_expect_equal "${output}" ""
111
112 db_path=${HOME}/database-path
113
114 test_begin_subtest "Absolute database path returned"
115 notmuch config set database.path ${HOME}/Maildir
116 test_expect_equal "$(notmuch config get database.path)" \
117                   "${HOME}/Maildir"
118
119 ln -s `pwd`/mail home/Maildir
120 add_email_corpus
121 test_begin_subtest "Relative database path expanded"
122 notmuch config set database.path Maildir
123 path=$(notmuch config get database.path | notmuch_dir_sanitize)
124 count=$(notmuch count '*')
125 test_expect_equal "${path} ${count}" \
126                   "CWD/home/Maildir 52"
127
128 test_begin_subtest "Add config to database"
129 notmuch new
130 key=g${RANDOM}.m${RANDOM}
131 value=${RANDOM}
132 notmuch config set --database ${key} ${value}
133 notmuch dump --include=config > OUTPUT
134 cat <<EOF > EXPECTED
135 #notmuch-dump batch-tag:3 config
136 #@ ${key} ${value}
137 EOF
138 test_expect_equal_file EXPECTED OUTPUT
139
140 test_begin_subtest "Roundtrip config to/from database"
141 notmuch new
142 key=g${RANDOM}.m${RANDOM}
143 value=${RANDOM}
144 notmuch config set --database ${key} ${value}
145 output=$(notmuch config get ${key})
146 test_expect_equal "${output}" "${value}"
147
148 test_begin_subtest "set built_with.* yields error"
149 test_expect_code 1 "notmuch config set built_with.compact false"
150
151 test_begin_subtest "get built_with.{compact,field_processor} prints true"
152 for key in compact field_processor; do
153     notmuch config get built_with.${key}
154 done > OUTPUT
155 cat <<EOF > EXPECTED
156 true
157 true
158 EOF
159 test_expect_equal_file EXPECTED OUTPUT
160
161 test_begin_subtest "get built_with.nonexistent prints false"
162 output=$(notmuch config get built_with.nonexistent)
163 test_expect_equal "$output" "false"
164
165 test_done