package web import ( "testing" "time" "gitea.dooplex.hu/admin/felhom-controller/internal/agentapi" "gitea.dooplex.hu/admin/felhom-controller/internal/settings" ) // „Later" is tonight 03:30 Budapest time — or tomorrow's when it is already past 03:30. func TestNextMediaLater(t *testing.T) { loc, _ := time.LoadLocation("Europe/Budapest") for now, want := range map[time.Time]string{ time.Date(2026, 10, 15, 21, 0, 0, 0, loc): "2026-10-16 03:30", time.Date(2026, 10, 15, 2, 0, 0, 0, loc): "2026-10-15 03:30", time.Date(2026, 10, 15, 3, 30, 0, 0, loc): "2026-10-16 03:30", } { if got := nextMediaLater(now).Format("2006-01-02 15:04"); got != want { t.Errorf("now %s: later = %s, want %s", now.Format(time.RFC3339), got, want) } } } // R-1044, the records measured on Tester 1 (Part G4): a pulled, registered disk keeps state „attached" with an EMPTY // backing device; the decision must read the backing device. COMPANION RED-PROOF: use `disk.State == "attached"` as // presence → the „gone" case fails (the box never notices the disk left — what rc.2 did on Tester 1). Restored. func TestEjectStep_G4(t *testing.T) { sp := settings.StoragePath{Path: "/mnt/felhom-drives/media_d", EjectedAt: "2026-10-15T08:10:20Z", EjectDurableID: "uuid:8a31"} in := agentapi.DiskInfo{DurableID: "uuid:8a31", State: "attached", BackingDevice: "/dev/sdd", MountPath: "/mnt/media_d", TotalBytes: 21474836480} gone := agentapi.DiskInfo{DurableID: "uuid:8a31", State: "attached", BackingDevice: "", MountPath: "/mnt/media_d"} if st, _ := ejectStep(sp, []agentapi.DiskInfo{in}); st != ejectWaitGone { t.Fatalf("still in the box right after the removal: want wait-gone, got %d", st) } if st, _ := ejectStep(sp, []agentapi.DiskInfo{gone}); st != ejectGone { t.Fatalf("pulled (state attached, no backing device): want gone, got %d", st) } sp.EjectSeenGone = true if st, _ := ejectStep(sp, []agentapi.DiskInfo{gone}); st != ejectWaitBack { t.Fatalf("still gone: want wait-back, got %d", st) } if st, d := ejectStep(sp, []agentapi.DiskInfo{in}); st != ejectBack || d == nil { t.Fatalf("plugged back: want back, got %d", st) } }