ci / test (pull_request) Successful in 55s
backup archives this machine's mail server -- its configuration and its data -- to <dir>/backups, whether the server runs in a container or on the host. It stops the server for a consistent archive and starts it again, a brief outage, so without --yes it only says what it would do. BackupKind, a pure classifier over the state, decides whether there is anything here to back up and refuses on a clustered node, whose real store lives in the cluster's PostgreSQL and S3 and is backed up there; a local archive would hold only its configuration. The container path reuses the existing read-only volume archiver; the host path tars the server directory. Each archive is verified as a readable, non-empty gzip tar before the command reports success. Restoring from a backup is deliberately left for later: it overwrites a live store, so it needs its own careful design and testing.
82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package apply
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/state"
|
|
)
|
|
|
|
func TestBackupKind(t *testing.T) {
|
|
removed := time.Now()
|
|
cases := []struct {
|
|
name string
|
|
st *state.State
|
|
wantKind string
|
|
wantRefuse string // a substring the refusal must mention, "" if it should not refuse
|
|
}{
|
|
{
|
|
name: "container server",
|
|
st: &state.State{Dir: "/var/lib/inbuxa", Shapes: map[string]string{"server": "container"}},
|
|
wantKind: "container",
|
|
},
|
|
{
|
|
name: "host server",
|
|
st: &state.State{Dir: "/var/lib/inbuxa", Shapes: map[string]string{"server": "host"}},
|
|
wantKind: "host",
|
|
},
|
|
{
|
|
name: "front ends only, server elsewhere",
|
|
st: &state.State{Shapes: map[string]string{"webmail": "container"}, ServerURL: "https://mail.example.org"},
|
|
wantRefuse: "another machine",
|
|
},
|
|
{
|
|
name: "no server here",
|
|
st: &state.State{Shapes: map[string]string{"webmail": "container"}},
|
|
wantRefuse: "not installed",
|
|
},
|
|
{
|
|
name: "server skipped",
|
|
st: &state.State{Shapes: map[string]string{"server": "skip"}},
|
|
wantRefuse: "not installed",
|
|
},
|
|
{
|
|
name: "uninstalled, data kept",
|
|
st: &state.State{Shapes: map[string]string{"server": "container"}, RemovedAt: &removed},
|
|
wantRefuse: "nothing is running",
|
|
},
|
|
{
|
|
name: "clustered node",
|
|
st: &state.State{Dir: "/var/lib/inbuxa", Shapes: map[string]string{"server": "container"}, Clustered: true},
|
|
wantRefuse: "shared store",
|
|
},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
kind, refuse := BackupKind(tc.st)
|
|
if tc.wantRefuse != "" {
|
|
if refuse == "" {
|
|
t.Fatalf("expected a refusal mentioning %q, got kind %q and no refusal", tc.wantRefuse, kind)
|
|
}
|
|
if kind != "" {
|
|
t.Errorf("a refusal should give no kind, got %q", kind)
|
|
}
|
|
if !strings.Contains(refuse, tc.wantRefuse) {
|
|
t.Errorf("refusal %q does not mention %q", refuse, tc.wantRefuse)
|
|
}
|
|
return
|
|
}
|
|
if refuse != "" {
|
|
t.Fatalf("did not expect a refusal, got %q", refuse)
|
|
}
|
|
if kind != tc.wantKind {
|
|
t.Errorf("kind = %q, want %q", kind, tc.wantKind)
|
|
}
|
|
})
|
|
}
|
|
}
|