package stacks import ( "strings" "testing" "gitea.dooplex.hu/admin/felhom-controller/internal/appbackup" ) // R-203 Scenario A/B — what the DEPLOY sets as ${USERDATA_PATH}, table-driven over both drive kinds. // This is the site the drill caught: on the system-data fallback the app bound a directory the // off-site capture set never looked at, and the run still reported ok. func TestWithPathVars_UserdataRootByDriveKind(t *testing.T) { const sys = "/mnt/sys_drive" const importRoot = "/mnt/sys_drive/felhom-data/userdata/import" cases := []struct{ name, hdd, want string }{ // Scenario B — enrolled drives: BYTE-IDENTICAL to pre-R-203. {"enrolled usb", "/mnt/felhom-usb", "/mnt/felhom-usb/userdata"}, {"enrolled hdd", "/mnt/felhom-drives/hdd_1", "/mnt/felhom-drives/hdd_1/userdata"}, // Scenario A — the system-data fallback: the canonical namespace root, which is what the // skeleton builder creates and what the capture set resolves against. {"system drive", "/mnt/sys_drive", "/mnt/sys_drive/felhom-data/userdata"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := withPathVars([]string{"DOMAIN=x"}, tc.hdd, sys, importRoot) want := "USERDATA_PATH=" + tc.want for _, e := range got { if e == want { return } } var actual string for _, e := range got { if strings.HasPrefix(e, "USERDATA_PATH=") { actual = e } } t.Fatalf("USERDATA_PATH = %q, want %q — the app would bind a directory the backup does not capture", actual, want) }) } } // The deploy-time bind and the backup-time capture root must be the SAME directory. Asserted against // the resolver the off-site capture set actually uses, so the two cannot drift apart again silently. func TestDeployBindMatchesCaptureRoot(t *testing.T) { const sys = "/mnt/sys_drive" for _, hdd := range []string{"/mnt/felhom-usb", "/mnt/felhom-drives/hdd_1", "/mnt/sys_drive"} { var bind string for _, e := range withPathVars(nil, hdd, sys, "") { if strings.HasPrefix(e, "USERDATA_PATH=") { bind = strings.TrimPrefix(e, "USERDATA_PATH=") } } captureRoot := appbackup.UserdataDir(appbackup.NamespaceRootFor(hdd, sys)) if bind != captureRoot { t.Fatalf("drive %q: deploy binds %q, backup captures %q", hdd, bind, captureRoot) } } }