Files

44 lines
1.6 KiB
Go

package backup
import (
"io"
"log"
"os"
"path/filepath"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
)
// R-668 (v0.269.0) — a registered storage path whose folder does not exist is NOT a second drive.
// Measured on 9202 2026-09-24: `scratch_hdd/userdata/romm` (removed that morning) was chosen as
// nextcloud's Tier-2 target — the stat in the same-disk check failed, which read as "another disk" — and
// the copy was written into a re-created folder on nextcloud's OWN disk. Runs the PRODUCTION same-disk
// check (no seam).
//
// COMPANION RED-PROOF (REPORT): remove the fail-closed stats in Manager.sameDevice — this test then fails
// at "chose the missing path".
func TestR668_MissingStoragePathIsNotASecondDrive(t *testing.T) {
tmp := t.TempDir()
live := filepath.Join(tmp, "drive")
missing := filepath.Join(tmp, "drive-gone")
if err := os.MkdirAll(live, 0o755); err != nil {
t.Fatal(err)
}
sett, err := settings.Load(filepath.Join(tmp, "settings.json"), log.New(io.Discard, "", 0))
if err != nil {
t.Fatal(err)
}
if err := sett.AddStoragePath(settings.StoragePath{Path: missing, Label: "gone", Schedulable: true}); err != nil {
t.Fatal(err)
}
m := &Manager{logger: log.New(io.Discard, "", 0), settings: sett, systemDataPath: filepath.Join(tmp, "no-sys")}
tgt, err := m.selectTier2TargetFrom("app", live, 1, 1)
if err == nil && tgt != nil && tgt.NamespaceRoot == NamespaceRoot(missing, true) {
t.Fatalf("chose the missing path %s as the second drive", missing)
}
if !m.sameDevice(live, missing) {
t.Fatal("an unreadable path must count as the SAME disk")
}
}