aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sync-mailbox-list/t
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sync-mailbox-list/t')
-rw-r--r--tests/sync-mailbox-list/t93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/sync-mailbox-list/t b/tests/sync-mailbox-list/t
new file mode 100644
index 0000000..ea80fbf
--- /dev/null
+++ b/tests/sync-mailbox-list/t
@@ -0,0 +1,93 @@
+# pre-create some mailboxes and susbscribe to some
+# foo: present on both, subscribed to both
+# bar: present on both, subscribed to local only
+# baz: present on both, subscribed to remote only
+# foo.bar: present on local only
+# foo.baz: present on remote only
+doveadm -u "local" mailbox create "foo" "bar" "baz" "foo.bar" "fo!o [b*a%r]"
+doveadm -u "local" mailbox subscribe "foo" "bar"
+doveadm -u "remote" mailbox create "foo" "bar" "baz" "foo~baz" "foo]bar"
+doveadm -u "remote" mailbox subscribe "foo" "baz"
+
+populate() {
+ local i
+ for ((i = 0; i < 32; i++)); do
+ m="$(shuf -n1 -e -- "foo" "bar" "baz" "foo.bar" "fo!o [b*a%r]")"
+ sample_message | deliver -u "local" -- -m "$m"
+
+ m="$(shuf -n1 -e -- "foo" "bar" "baz" "foo~baz" "foo]bar")"
+ sample_message | deliver -u "remote" -- -m "$m"
+ done
+}
+verify() {
+ check_mailbox_list || error
+ check_mailboxes_status "foo" "bar" "baz" "foo.bar" "foo.baz" "INBOX" "fo!o [b*a%r]" "foo]bar"
+}
+populate
+
+step_start "pre-subscribtions"
+interimap_init
+grep -Fx "local: Subscribe to baz" <"$STDERR" || error
+grep -Fx "remote: Subscribe to bar" <"$STDERR" || error
+grep -Fx "local: Created mailbox foo.baz" <"$STDERR" || error
+grep -Fx "remote: Created mailbox foo~bar" <"$STDERR" || error
+step_done
+
+# ensure the mailbox list is synchronized
+step_start "mailbox list and content"
+verify
+check_mailbox_list -s
+step_done
+
+
+# delete a mailbox on one server and verify that synchronization fails as it's still in the database
+step_start "aborts if present in database"
+for u in "local" "remote"; do
+ [ "$u" = "local" ] && { m="foo.bar"; m2="$m"; } || { m="foo.baz"; m2="foo~baz"; }
+
+ doveadm -u "$u" mailbox delete "$m2"
+ ! interimap || error
+ grep -Fx "database: ERROR: Mailbox $m exists. Run \`interimap --target=database --delete $m\` to delete." <"$STDERR"
+
+ interimap --target="database" --delete "$m" || error
+ grep -Fx "database: Removed mailbox $m" <"$STDERR" || error
+
+ interimap || error # create again
+ grep -Fx "database: Created mailbox $m" <"$STDERR" || error
+ grep -Fx "$u: Created mailbox $m2" <"$STDERR" || error
+done
+verify
+check_mailbox_list -s
+step_done
+
+
+
+# (un)subscribe from some mailboxes, including a non-existent one
+step_start "new (un)subscribtions"
+doveadm -u "local" mailbox unsubscribe "foo"
+doveadm -u "remote" mailbox unsubscribe "bar"
+doveadm -u "local" mailbox subscribe "foo.bar" "foo.nonexistent" "foo.baz"
+doveadm -u "remote" mailbox subscribe "foo~bar" "bar~nonexistent"
+populate
+
+interimap
+grep -Fx "remote: Unsubscribe to foo" <"$STDERR"
+grep -Fx "local: Unsubscribe to bar" <"$STDERR"
+grep -Fx "remote: Subscribe to foo~baz" <"$STDERR"
+verify
+check_mailbox_list -s $(doveadm -u "local" mailbox list) # exclude "foo.nonexistent" and "bar~nonexistent"
+
+# check that "baz", "foo.bar" and "foo.baz" are the only subscribed mailboxes
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/count" <<-EOF
+ SELECT COUNT(*)
+ FROM mailboxes
+ WHERE subscribed <> (mailbox IN (
+ x'$(printf "%s" "baz" | xxd -ps)',
+ x'$(printf "%s\\0%s" "foo" "bar" | xxd -ps)',
+ x'$(printf "%s\\0%s" "foo" "baz" | xxd -ps)'
+ ))
+EOF
+[ $(< "$TMPDIR/count") -eq 0 ] || error
+step_done
+
+# vim: set filetype=sh :