package host import ( "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/provision" "testing" ) func TestPlan14MigrationRefusesEveryMovePhase(t *testing.T) { for _, state := range []string{provision.MovePreparing, provision.MoveReady, provision.MoveCutting, provision.MoveAborting, provision.MoveReverting, provision.MoveLanding, provision.MoveCommitted, provision.MoveRollingBack, provision.MoveStuck, "future", ""} { for _, phase := range []string{"", provision.LandChecking, provision.LandProbing, provision.LandProbed} { rec := provision.Record{Move: &provision.MoveState{State: state, LandingPhase: phase}} if err := rootMigrationPreflight(true, []provision.Record{rec}, nil); err == nil { t.Fatalf("accepted %s/%s", state, phase) } } } for _, op := range []hostclaim.Op{{ID: "admitted-before-launch"}, {Kind: "recovering"}, {Phase: "future"}} { if err := rootMigrationPreflight(true, nil, []hostclaim.Claim{{Op: op}}); err == nil { t.Fatalf("accepted orphan operation %+v", op) } } if err := rootMigrationPreflight(false, nil, nil); err == nil { t.Fatal("accepted unknown census") } if err := rootMigrationPreflight(true, []provision.Record{{}}, []hostclaim.Claim{{}}); err != nil { t.Fatal(err) } serving := hostclaim.Claim{Op: hostclaim.Op{Kind: hostclaim.KindServing, Exec: "box", Participants: []string{"box"}}} if err := rootMigrationPreflight(true, []provision.Record{{}}, []hostclaim.Claim{serving}); err != nil { t.Fatalf("idle serving session refused migration: %v", err) } serving.Op.ID = "unfinished" if err := rootMigrationPreflight(true, nil, []hostclaim.Claim{serving}); err == nil { t.Fatal("serving kind hid an unfinished operation") } }