package host import ( "testing" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostguard" "github.com/carlosframework/platform/internal/instancectl" ) func TestPlan14RetiredExecutionClosure(t *testing.T) { for _, mode := range []string{"retired", "live", "foreign host", "foreign stamp", "barrier", "open writers", "unsettled unit", "foreign unit", "unfinished role", "bad completion"} { t.Run(mode, func(t *testing.T) { target := hostguard.FenceTarget{Host: "shop.example", Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "en", BootID: "boot", ControllerID: "controller"} view := hostguard.FenceView{Host: target.Host, Retired: []hostguard.Captured{{Incarnation: target.Incarnation, Stamp: target.Stamp}}} launch := hostbox.LaunchInventory{Target: target, WritersClosed: true, Reservations: []hostbox.LaunchReservation{{Target: target, State: hostbox.UnitSettled, Group: hostbox.LaunchGroup{RelativePath: instancectl.ClaimUnitControlGroup(target.Host)}}}} switch mode { case "live": view.Retired = nil case "foreign host": view.Host = "other.example" case "foreign stamp": view.Retired[0].Stamp++ case "barrier": view.Barrier = &target case "open writers": launch.WritersClosed = false case "unsettled unit": launch.Reservations[0].State = hostbox.UnitStarted case "foreign unit": launch.Reservations[0].Target.Session++ case "unfinished role": launch.Reservations[0].State = "started" case "bad completion": launch.Completed.Count = 1 } done, err := retiredExecutionLaunch(view, launch) if mode == "retired" { if !done || err != nil { t.Fatalf("retired closure: %v %v", done, err) } } else if mode == "live" || mode == "foreign stamp" { if done || err != nil { t.Fatalf("live closure bypassed: %v %v", done, err) } } else if err == nil { t.Fatal("unproven closure accepted") } }) } }