Files
jcoffey-dev 595c17a3b7 inbuxa uninstall: the programs go, the data stays unless --purge
`inbuxa uninstall [--dry-run] [--yes] [--purge]` takes away what the
installer put on this machine: the compose project's containers, the
units, the server's binary and the older ones kept for rollback, the
console's and the webmail's files, the webmail's user, the installer's
own Node. The data stays -- the server's volumes or its directory and
user, Caddy's certificates, credentials.txt, .env, dns.zone -- and the
install record, marked removed, so `install` run again with the same
options converges onto it: the same mailboxes, no first boot.

--purge takes the data too, volumes by name as well (after an uninstall
that kept them there is no compose file left to name them), all but
<dir>/backups, which it names for the operator to delete. Docker, other
distribution packages and the configuration an operator's own web server
loads are never touched; the last is said, as is a joined server that
still lists these front ends. One component off is `install` with it
skipped, and uninstall says so rather than doing it a second way.

status says what was uninstalled and what was kept; upgrade has nothing
to do on it.

Tests: what is removed and kept, with and without --purge, in each
shape. e2e: uninstall-containers 22/22 (a dry run and a run without --yes
change nothing; uninstalled with volumes, credentials and backups kept;
installed again with the same mailbox signing in; purged to the backups
alone), uninstall-host 14/14 (units, binaries, the webmail's user and
Node gone, the server's data and user kept, back again, then purged).
upgrade-containers, install-local, install-host, status-export, topology,
interface, all-host and webmail-host pass.
2026-10-12 13:40:07 -07:00

61 lines
2.1 KiB
Go

// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
// SPDX-License-Identifier: AGPL-3.0-or-later
package apply
import (
"os"
"path/filepath"
"strings"
"testing"
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/state"
)
func TestUninstallKeepsTheDataUnlessPurged(t *testing.T) {
dir := t.TempDir()
os.WriteFile(filepath.Join(dir, "compose.yaml"), []byte("services:\n server:\n caddy:\n"), 0o640)
os.MkdirAll(filepath.Join(dir, "backups"), 0o700)
st := &state.State{Dir: dir, Shapes: map[string]string{"server": "container", "console": "container", "webmail": "container"}}
r := UninstallPlan(st, false)
all := func(l []string) string { return strings.Join(l, "\n") }
if !strings.Contains(all(r.Remove), "containers") {
t.Errorf("remove = %v", r.Remove)
}
for _, want := range []string{"inbuxa_inbuxa-data", "Caddy's volumes", "credentials.txt", "backups", "marked removed"} {
if !strings.Contains(all(r.Keep), want) {
t.Errorf("kept lacks %q: %v", want, r.Keep)
}
}
r = UninstallPlan(st, true)
for _, want := range []string{"inbuxa_inbuxa-data", "Caddy's volumes", "credentials.txt", "the install record"} {
if !strings.Contains(all(r.Remove), want) {
t.Errorf("purge does not remove %q: %v", want, r.Remove)
}
}
if !strings.Contains(all(r.Keep), "backups") {
t.Error("purge would take the backups")
}
}
func TestUninstallOnTheHost(t *testing.T) {
st := &state.State{Dir: t.TempDir(), Shapes: map[string]string{"server": "host", "console": "host", "webmail": "host"},
ServerURL: ""}
r := UninstallPlan(st, false)
all := strings.Join(r.Remove, "\n")
for _, want := range []string{HostServerUnit, HostWebmailUnit, "console's files"} {
if !strings.Contains(all, want) {
t.Errorf("remove lacks %q: %v", want, r.Remove)
}
}
if !strings.Contains(strings.Join(r.Keep, "\n"), "/server (the server's configuration and mail)") {
t.Errorf("the host server's data is not kept: %v", r.Keep)
}
st.ServerURL = "https://mail.example.org"
if r := UninstallPlan(st, false); !strings.Contains(strings.Join(r.Notes, "\n"), "still lists these front ends") {
t.Errorf("a joined machine's note is missing: %v", r.Notes)
}
}