aboutsummaryrefslogtreecommitdiffstats
path: root/tests/rename-inferiors
diff options
context:
space:
mode:
Diffstat (limited to 'tests/rename-inferiors')
-rw-r--r--tests/rename-inferiors/local.conf3
-rw-r--r--tests/rename-inferiors/remote.conf3
-rw-r--r--tests/rename-inferiors/t100
3 files changed, 106 insertions, 0 deletions
diff --git a/tests/rename-inferiors/local.conf b/tests/rename-inferiors/local.conf
new file mode 100644
index 0000000..b56cc70
--- /dev/null
+++ b/tests/rename-inferiors/local.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = .
+}
diff --git a/tests/rename-inferiors/remote.conf b/tests/rename-inferiors/remote.conf
new file mode 100644
index 0000000..2d08a24
--- /dev/null
+++ b/tests/rename-inferiors/remote.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = ^
+}
diff --git a/tests/rename-inferiors/t b/tests/rename-inferiors/t
new file mode 100644
index 0000000..9267e6f
--- /dev/null
+++ b/tests/rename-inferiors/t
@@ -0,0 +1,100 @@
+doveadm -u "local" mailbox create "root.from" "root.from.child" "root.from.child2" "root.from.child.grandchild"
+doveadm -u "remote" mailbox create "root^sibbling" "root^sibbling^grandchild" "root2"
+
+for m in "root.from" "root.from.child" "root.from.child2" "root.from.child.grandchild" "INBOX"; do
+ sample_message | deliver -u "local" -- -m "$m"
+done
+for m in "root^sibbling" "root^sibbling^grandchild" "root2" "INBOX"; do
+ sample_message | deliver -u "remote" -- -m "$m"
+done
+
+interimap_init
+check_mailboxes_status "root.from" "root.from.child" "root.from.child2" "root.from.child.grandchild" \
+ "root.sibbling" "root.sibbling.grandchild" "root2" "INBOX"
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes.csv" <<-EOF
+ .mode csv
+ SELECT idx, hex(mailbox)
+ FROM mailboxes
+ ORDER BY idx
+EOF
+
+step_start "non-existent source (no-op)"
+interimap --rename "nonexistent" "root" || error "Renamed non-existent mailbox?"
+check_mailbox_list
+step_done
+
+step_start "\\NonExistent target (fail)"
+! interimap --rename "root2" "root" || error "Didn't abort on ALREADYEXISTS"
+grep -E "^local: ERROR: Couldn't rename mailbox root2: NO \[ALREADYEXISTS\] " <"$STDERR"
+check_mailbox_list
+step_done
+
+
+# rename 'root.from' to 'from.root', including inferiors
+step_start "existing source with inferiors"
+interimap --rename "root.from" "from.root"
+grep -Fx 'local: Renamed mailbox root.from to from.root' <"$STDERR"
+grep -Fx 'remote: Renamed mailbox root^from to from^root' <"$STDERR"
+grep -Fx 'database: Renamed mailbox root.from to from.root' <"$STDERR"
+
+check_mailbox_list
+check_mailboxes_status "from.root" "from.root.child" "from.root.child2" "from.root.child.grandchild" \
+ "root.sibbling" "root.sibbling.grandchild" "root2" "INBOX"
+
+before="$(printf "%s\\0%s" "root" "from" | xxd -u -ps)"
+after="$(printf "%s\\0%s" "from" "root" | xxd -u -ps)"
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes2.csv" <<-EOF
+ .mode csv
+ SELECT idx,
+ CASE
+ WHEN mailbox = x'$after' OR hex(mailbox) LIKE '${after}00%'
+ THEN '$before' || SUBSTR(hex(mailbox), $((${#after}+1)))
+ ELSE hex(mailbox)
+ END
+ FROM mailboxes
+ ORDER BY idx
+EOF
+diff -u --label="a/mailboxes.csv" --label="b/mailboxes.csv" \
+ "$TMPDIR/mailboxes.csv" "$TMPDIR/mailboxes2.csv" \
+ || error "Mailbox list differs"
+step_done
+
+
+# rename \NonExistent root and check that its children move
+step_start "\\NonExistent source with inferiors"
+interimap --rename "root" "newroot"
+grep -Fq 'local: Renamed mailbox root to newroot' <"$STDERR"
+grep -Fq 'remote: Renamed mailbox root to newroot' <"$STDERR"
+grep -Fq 'database: Renamed mailbox root to newroot' <"$STDERR"
+
+check_mailbox_list
+check_mailboxes_status "from.root" "from.root.child" "from.root.child2" "from.root.child.grandchild" \
+ "newroot.sibbling" "newroot.sibbling.grandchild" "root2" "INBOX"
+
+before2="$(printf "%s" "root" | xxd -u -ps)"
+after2="$(printf "%s" "newroot" | xxd -u -ps)"
+sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes3.csv" <<-EOF
+ .mode csv
+ SELECT idx,
+ CASE
+ WHEN mailbox = x'$after' OR hex(mailbox) LIKE '${after}00%'
+ THEN '$before' || SUBSTR(hex(mailbox), $((${#after}+1)))
+ WHEN hex(mailbox) LIKE '${after2}00%'
+ THEN '$before2' || SUBSTR(hex(mailbox), $((${#after2}+1)))
+ ELSE hex(mailbox)
+ END
+ FROM mailboxes
+ ORDER BY idx
+EOF
+diff -u --label="a/mailboxes.csv" --label="b/mailboxes.csv" \
+ "$TMPDIR/mailboxes2.csv" "$TMPDIR/mailboxes3.csv" \
+ || error "Mailbox list differs"
+step_done
+
+
+interimap
+check_mailbox_list
+check_mailboxes_status "from.root" "from.root.child" "from.root.child2" "from.root.child.grandchild" \
+ "newroot.sibbling" "newroot.sibbling.grandchild" "root2" "INBOX"
+
+# vim: set filetype=sh :