aboutsummaryrefslogtreecommitdiffstats
path: root/tests/resume/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/resume/t
parentb9da6cc7ecf71026d1023dc3354b820c7518426e (diff)
Refactor and improve test suite.
Diffstat (limited to 'tests/resume/t')
-rw-r--r--tests/resume/t98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/resume/t b/tests/resume/t
new file mode 100644
index 0000000..cb0208c
--- /dev/null
+++ b/tests/resume/t
@@ -0,0 +1,98 @@
+# create and populate a bunch of mailboxes
+doveadm -u "local" mailbox create "foo" "foo.bar" "baz"
+for ((i = 0; i < 8; i++)); do
+ sample_message | deliver -u "local" -- -m "foo"
+ sample_message | deliver -u "local" -- -m "foo.bar"
+ sample_message | deliver -u "local" -- -m "INBOX"
+done
+interimap_init
+check_mailbox_list
+check_mailboxes_status "foo" "foo.bar" "baz" "INBOX"
+
+# spoof UIDNEXT in the database
+set_uidnext() {
+ local imap="$1" mailbox="$2" uidnext="$3"
+ sqlite3 "$XDG_DATA_HOME/interimap/remote.db" <<-EOF
+ UPDATE $imap
+ SET UIDNEXT = $uidnext
+ WHERE idx = (
+ SELECT idx
+ FROM mailboxes
+ WHERE mailbox = x'$mailbox'
+ );
+ EOF
+}
+
+# spoof "foo"'s UIDVALIDITY and UIDNEXT values
+uidvalidity="$(doveadm -u "local" -f flow mailbox status uidvalidity "foo" | sed 's/.*=//')"
+[ $uidvalidity -eq 4294967295 ] && uidvalidity2=1 || uidvalidity2=$((uidvalidity+1))
+doveadm -u "local" mailbox update --uid-validity "$uidvalidity2" "foo"
+set_uidnext "local" "$(printf "%s" "foo" | xxd -ps)" 1
+
+# verify that interimap chokes on the UIDVALIDITY change without doing any changes
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump.sql" <<-EOF
+ .dump
+EOF
+doveadm -u "local" mailbox status "all" "foo" >"$TMPDIR/foo.local"
+doveadm -u "remote" mailbox status "all" "foo" >"$TMPDIR/foo.remote"
+
+! interimap || error
+grep -Fx "Resuming interrupted sync for foo" <"$STDERR"
+grep -Fx "local(foo): ERROR: UIDVALIDITY changed! ($uidvalidity2 != $uidvalidity) Need to invalidate the UID cache." <"$STDERR"
+
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump2.sql" <<-EOF
+ .dump
+EOF
+doveadm -u "local" mailbox status "all" "foo" >"$TMPDIR/foo.local2"
+doveadm -u "remote" mailbox status "all" "foo" >"$TMPDIR/foo.remote2"
+
+diff -u --label="a/dump.sql" --label="b/dump.sql" "$TMPDIR/dump2.sql" "$TMPDIR/dump.sql"
+diff -u --label="a/foo.local" --label="b/foo.remote" "$TMPDIR/foo.local" "$TMPDIR/foo.local2"
+diff -u --label="a/foo.local" --label="b/foo.remote" "$TMPDIR/foo.remote" "$TMPDIR/foo.remote2"
+
+
+# spoof UIDNEXT values for INBOX (local+remote) and foo.bar (remote)
+set_uidnext "local" "$(printf "%s" "INBOX" | xxd -ps)" 2
+set_uidnext "remote" "$(printf "%s" "INBOX" | xxd -ps)" 2
+set_uidnext "remote" "$(printf "%s\\0%s" "foo" "bar" | xxd -ps)" 0
+
+# set some flags and remove some messages for UIDs >2
+doveadm -u "local" flags add "\\Seen" mailbox "INBOX" 6,7
+doveadm -u "remote" flags add "\\Deleted" mailbox "INBOX" 6,8
+
+doveadm -u "local" expunge mailbox "INBOX" 4,5
+doveadm -u "remote" expunge mailbox "INBOX" 3,4
+doveadm -u "remote" expunge mailbox "foo~bar" 5
+
+# add new messages
+sample_message | deliver -u "local" -- -m "foo.bar"
+sample_message | deliver -u "remote" -- -m "foo~bar"
+sample_message | deliver -u "local" -- -m "baz"
+
+interimap "foo.bar" "InBoX" "baz" # ignore "foo"
+grep -Fx "Resuming interrupted sync for foo.bar" <"$STDERR"
+grep -Fx "Resuming interrupted sync for INBOX" <"$STDERR"
+check_mailbox_list
+check_mailboxes_status "foo.bar" "INBOX" "baz" # ignore "foo"
+
+
+# count entries in the mapping table
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/count" <<-EOF
+ SELECT COUNT(*)
+ FROM mapping NATURAL JOIN mailboxes
+ WHERE mailbox != x'$(printf "%s" "foo" | xxd -ps)'
+ GROUP BY idx
+ ORDER BY mailbox;
+EOF
+
+# count messages:
+# INBOX: 8-2-1 = 5
+# baz: 1
+# foo.bar: 8-1+1+1 = 9
+diff -u --label="a/count" --label="b/count" "$TMPDIR/count" - <<-EOF
+ 5
+ 1
+ 9
+EOF
+
+# vim: set filetype=sh :