| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "github.com/carlosframework/platform/internal/hostclaim" |
| 5 | "github.com/carlosframework/platform/internal/provision" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestPlan14MigrationRefusesEveryMovePhase(t *testing.T) { |
| 10 | for _, state := range []string{provision.MovePreparing, provision.MoveReady, provision.MoveCutting, provision.MoveAborting, provision.MoveReverting, provision.MoveLanding, provision.MoveCommitted, provision.MoveRollingBack, provision.MoveStuck, "future", ""} { |
| 11 | for _, phase := range []string{"", provision.LandChecking, provision.LandProbing, provision.LandProbed} { |
| 12 | rec := provision.Record{Move: &provision.MoveState{State: state, LandingPhase: phase}} |
| 13 | if err := rootMigrationPreflight(true, []provision.Record{rec}, nil); err == nil { |
| 14 | t.Fatalf("accepted %s/%s", state, phase) |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | for _, op := range []hostclaim.Op{{ID: "admitted-before-launch"}, {Kind: "recovering"}, {Phase: "future"}} { |
| 19 | if err := rootMigrationPreflight(true, nil, []hostclaim.Claim{{Op: op}}); err == nil { |
| 20 | t.Fatalf("accepted orphan operation %+v", op) |
| 21 | } |
| 22 | } |
| 23 | if err := rootMigrationPreflight(false, nil, nil); err == nil { |
| 24 | t.Fatal("accepted unknown census") |
| 25 | } |
| 26 | if err := rootMigrationPreflight(true, []provision.Record{{}}, []hostclaim.Claim{{}}); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | serving := hostclaim.Claim{Op: hostclaim.Op{Kind: hostclaim.KindServing, Exec: "box", Participants: []string{"box"}}} |
| 30 | if err := rootMigrationPreflight(true, []provision.Record{{}}, []hostclaim.Claim{serving}); err != nil { |
| 31 | t.Fatalf("idle serving session refused migration: %v", err) |
| 32 | } |
| 33 | serving.Op.ID = "unfinished" |
| 34 | if err := rootMigrationPreflight(true, nil, []hostclaim.Claim{serving}); err == nil { |
| 35 | t.Fatal("serving kind hid an unfinished operation") |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | |