aboutsummaryrefslogtreecommitdiffstats
path: root/tests/delete
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/delete
parentb9da6cc7ecf71026d1023dc3354b820c7518426e (diff)
Refactor and improve test suite.
Diffstat (limited to 'tests/delete')
-rw-r--r--tests/delete/local.conf3
-rw-r--r--tests/delete/remote.conf3
-rw-r--r--tests/delete/t95
3 files changed, 101 insertions, 0 deletions
diff --git a/tests/delete/local.conf b/tests/delete/local.conf
new file mode 100644
index 0000000..b56cc70
--- /dev/null
+++ b/tests/delete/local.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = .
+}
diff --git a/tests/delete/remote.conf b/tests/delete/remote.conf
new file mode 100644
index 0000000..2d08a24
--- /dev/null
+++ b/tests/delete/remote.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = ^
+}
diff --git a/tests/delete/t b/tests/delete/t
new file mode 100644
index 0000000..c38d4d3
--- /dev/null
+++ b/tests/delete/t
@@ -0,0 +1,95 @@
+doveadm -u "local" mailbox create "foo.bar" "foo.bar.baz"
+
+for m in "foo.bar" "foo.bar.baz" "INBOX"; do
+ sample_message | deliver -u "local" -- -m "$m"
+done
+
+interimap_init
+check_mailbox_list
+check_mailboxes_status "foo.bar" "foo.bar.baz" "INBOX"
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump.sql" <<-EOF
+ .dump
+EOF
+
+
+step_start "nonexistent source (no-op)"
+interimap --target="local,remote" --target="database" --delete "nonexistent" || error
+
+check_mailbox_list
+check_mailboxes_status "foo.bar" "foo.bar.baz" "INBOX"
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump2.sql" <<-EOF
+ .dump
+EOF
+diff -u --label="a/dump.sql" --label="b/dump.sql" \
+ "$TMPDIR/dump.sql" "$TMPDIR/dump2.sql" || error "SQL dumps differ"
+step_done
+
+
+# foo.bar will become \NoSelect in local, per RFC 3501: "It is permitted
+# to delete a name that has inferior hierarchical names and does not
+# have the \Noselect mailbox name attribute. In this case, all messages
+# in that mailbox are removed, and the name will acquire the \Noselect
+# mailbox name attribute."
+step_start "mailbox with inferiors"
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes.sql" <<-EOF
+ SELECT idx, mailbox FROM mailboxes
+ WHERE mailbox != x'$(printf "%s\\0%s" "foo" "bar" | xxd -ps)'
+ ORDER BY idx
+EOF
+
+interimap --target="local" --delete "foo.bar"
+
+check_mailbox_list
+check_mailboxes_status "foo.bar.baz" "INBOX"
+
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump2.sql" <<-EOF
+ .dump
+EOF
+diff -u --label="a/dump.sql" --label="b/dump.sql" \
+ "$TMPDIR/dump.sql" "$TMPDIR/dump2.sql" || error "SQL dumps differ"
+
+! doveadm -u "local" mailbox status uidvalidity "foo.bar" # gone
+ doveadm -u "remote" mailbox status uidvalidity "foo^bar"
+
+# now delete from the remote server and the database
+interimap --delete "foo.bar"
+
+! doveadm -u "local" mailbox status uidvalidity "foo.bar"
+! doveadm -u "remote" mailbox status uidvalidity "foo^bar"
+
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes2.sql" <<-EOF
+ SELECT idx, mailbox FROM mailboxes ORDER BY idx
+EOF
+diff -u --label="a/mailboxes.sql" --label="b/mailboxes.sql" \
+ "$TMPDIR/mailboxes.sql" "$TMPDIR/mailboxes2.sql" || error "SQL dumps differ"
+
+check_mailbox_list
+check_mailboxes_status "foo.bar.baz" "INBOX"
+step_done
+
+
+step_start "INBOX (fail)"
+! interimap --delete "InBoX" || error "deleted INBOX"
+grep -Fx "ERROR: INBOX can't be deleted" <"$STDERR" || error
+
+check_mailbox_list
+check_mailboxes_status "foo.bar.baz" "INBOX"
+step_done
+
+
+step_start "\\Noinferiors mailbox"
+interimap --delete "foo.bar.baz"
+
+! doveadm -u "local" mailbox status uidvalidity "foo.bar.baz"
+! doveadm -u "remote" mailbox status uidvalidity "foo^bar^baz"
+
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/count" <<-EOF
+ SELECT COUNT(*) FROM mailboxes
+EOF
+[ "$(< "$TMPDIR/count" )" -eq 1 ] || error "Not only INBOX left?"
+
+check_mailbox_list
+check_mailboxes_status "INBOX"
+step_done
+
+# vim: set filetype=sh :