Files
stalwart-migrator/internal/backup/fdbbackup_test.go
T
jcoffey-dev 4b0bec8956 Add SPDX headers to every Go file
GPLv3's "How to Apply These Terms" asks for a notice in each source file;
this is the modern two-line SPDX form of it rather than the full paragraph.
82 files, including tests.

The blank line after the header is load-bearing. In Go a comment block
immediately preceding `package X` becomes the package doc comment, so
without the separator the SPDX lines would be absorbed into the doc for the
eleven packages whose doc.go (or main.go) opens with one, and `go doc` would
print them. Verified it doesn't.
2026-08-23 18:03:15 -07:00

52 lines
1.8 KiB
Go

// SPDX-FileCopyrightText: 2026 LINUXexpert-org
// SPDX-License-Identifier: GPL-3.0-or-later
package backup
import (
"context"
"strings"
"testing"
)
func TestBuildFDBBackupStartArgs(t *testing.T) {
args := BuildFDBBackupStartArgs(FDBOptions{ClusterFile: "/etc/foundationdb/fdb.cluster", Destination: "file:///var/backups/stalwart-fdb", Tag: "stalwart-migrate"})
joined := strings.Join(args, " ")
for _, want := range []string{"start", "-C /etc/foundationdb/fdb.cluster", "-d file:///var/backups/stalwart-fdb", "-t stalwart-migrate"} {
if !strings.Contains(joined, want) {
t.Errorf("BuildFDBBackupStartArgs = %q, missing %q", joined, want)
}
}
}
func TestBuildFDBBackupStartArgsDefaultTag(t *testing.T) {
args := BuildFDBBackupStartArgs(FDBOptions{Destination: "file:///var/backups/stalwart-fdb"})
joined := strings.Join(args, " ")
if !strings.Contains(joined, "-t default") {
t.Errorf("BuildFDBBackupStartArgs = %q, want default tag when none given", joined)
}
}
func TestStartFDBBackupInvokesFdbbackup(t *testing.T) {
dir := t.TempDir()
log := argsFile(t, dir)
withFakeExecutable(t, "fdbbackup", fakeScriptLoggingArgs(log, "exit 0"))
err := StartFDBBackup(context.Background(), FDBOptions{Destination: "file:///var/backups/stalwart-fdb"})
if err != nil {
t.Fatalf("StartFDBBackup: %v", err)
}
got := readArgsFile(t, log)
if !strings.Contains(got, "start") || !strings.Contains(got, "-d file:///var/backups/stalwart-fdb") {
t.Errorf("fdbbackup was invoked with %q", got)
}
}
func TestStartFDBBackupPropagatesFailure(t *testing.T) {
withFakeExecutable(t, "fdbbackup", "#!/bin/sh\necho 'cluster unreachable' >&2\nexit 1\n")
err := StartFDBBackup(context.Background(), FDBOptions{Destination: "file:///var/backups/stalwart-fdb"})
if err == nil {
t.Fatal("StartFDBBackup should error when fdbbackup exits non-zero")
}
}