aboutsummaryrefslogtreecommitdiffstats
path: root/tests/list-mailbox/t
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-11-09 03:13:45 +0100
committerGuilhem Moulin <guilhem@fripost.org>2019-11-13 06:23:56 +0100
commit67440844c422ee30b31df9a46a7f99ac0e833add (patch)
tree989381e5b94d5939dafdd1e99c7db2ada95355ec /tests/list-mailbox/t
parentb9da6cc7ecf71026d1023dc3354b820c7518426e (diff)
Refactor and improve test suite.
Diffstat (limited to 'tests/list-mailbox/t')
-rw-r--r--tests/list-mailbox/t57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/list-mailbox/t b/tests/list-mailbox/t
new file mode 100644
index 0000000..e905537
--- /dev/null
+++ b/tests/list-mailbox/t
@@ -0,0 +1,57 @@
+# create and populate some mailboxes locally
+declare -a MAILBOXES=( "foo" "foo bar" "f\\\"o!o.bar" "f.o.o" )
+doveadm -u "local" mailbox create -- "${MAILBOXES[@]}" "foobad" "baz" "INBOX"
+for ((i = 0; i < 32; i++)); do
+ m="$(shuf -n1 -e -- "${MAILBOXES[@]}" "foobad" "baz" "INBOX")"
+ sample_message | deliver -u "local" -- -m "$m"
+done
+
+interimap_init
+for m in "${MAILBOXES[@]}"; do
+ grep -Fx "remote: Created mailbox ${m//./?}" <"$STDERR" || error "${m//./?}"
+ grep -Fx "database: Created mailbox $m" <"$STDERR" || error
+done
+
+# also check inferiors in the list, but exclude "foobad" and "baz"
+check_mailbox_list "${MAILBOXES[@]}" "INBOX" "f\\\"o!o" "f" "f.o"
+check_mailboxes_status "${MAILBOXES[@]}" || error
+
+# double check that "foobad" and "baz" weren't created
+! doveadm -u "remote" mailbox status uidvalidity "foobad" || error
+! doveadm -u "remote" mailbox status uidvalidity "baz" || error
+
+# check that "foobad" and "INBOX" aren't in the database
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/count" <<-EOF
+ SELECT COUNT(*)
+ FROM mailboxes
+ WHERE mailbox = x'$(printf "%s" "foobad" | xxd -u -ps)'
+ OR mailbox = x'$(printf "%s" "INBOX" | xxd -u -ps)'
+ OR mailbox = x'$(printf "%s" "baz" | xxd -u -ps)'
+EOF
+[ $(< "$TMPDIR/count") -eq 0 ] || error
+
+
+# mailbox given on the command line overrides list-mailbox
+sample_message | deliver -u "local" -- -m "foobad"
+sample_message | deliver -u "local" -- -m "foo"
+interimap "foobad" || error
+! grep -F "remote(foo): Added 1 UID(s)" <"$STDERR" || error
+check_mailbox_list "foobad"
+check_mailbox_status "foobad"
+
+interimap "foo" || error
+grep -F "remote(foo): Added 1 UID(s)" <"$STDERR" || error
+check_mailbox_status "foo"
+! check_mailbox_list "baz"
+
+
+# finally, try a bunch of invalid 'list-mailbox' values to test the parser:
+# empty string, missing space between values, unterminated string
+for v in '""' '"f o o""bar"' '"f o o" "bar" "baz\" x'; do
+ sed -ri "s/^(list-mailbox\\s*=\\s*).*/\\1${v//\\/\\\\}/" \
+ "$XDG_CONFIG_HOME/interimap/config"
+ ! interimap || error
+ grep -xF "Invalid value for list-mailbox: $v" <"$STDERR"
+done
+
+# vim: set filetype=sh :