| 1 | package hostops |
| 2 | |
| 3 | import ( |
| 4 | "github.com/carlosframework/platform/internal/hostclaim" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestPlan12LossOwnerPolicy(t *testing.T) { |
| 9 | for _, bad := range []string{"", "stamp", "executor", "rollback", "coverage", "intent"} { |
| 10 | in := moveLossIntent{Kind: moveLossIntentKind, Move: "move", Incarnation: "inc", Rollback: "rb_abcdefghijklmnopqrstuvwxyz", Target: "target", Source: "source", TargetRegion: "uk", SourceRegion: "ie", RecordKey: "record", RecordETag: "etag", RecordState: moveLossRecordLanding} |
| 11 | raw, _ := in.encode() |
| 12 | r := hostclaim.LossRecord{ID: "loss_1", OpID: "move", Box: "target", HolderIncarnation: "inc", ConfirmedConsequences: hostclaim.LossConsequences{RecoveryIntent: raw}} |
| 13 | c := hostclaim.Claim{Holder: &hostclaim.Holder{Incarnation: "inc", Key: "record", Stamp: 7}, Op: hostclaim.Op{Kind: hostclaim.KindRestoring, ID: "move", Phase: hostclaim.PhaseProbing, Exec: "source", Intent: map[string]string{"source": "source", "target": "target", "to": "uk", "rollback": in.Rollback}, Journal: map[string]string{hostclaim.JournalSourceStamp: "7", "lost_target_released": "loss_1"}}} |
| 14 | a := hostclaim.Admission{Box: "source", Region: "ie", Mode: "cold"} |
| 15 | switch bad { |
| 16 | case "stamp": |
| 17 | c.Holder.Stamp++ |
| 18 | case "executor": |
| 19 | c.Op.Exec = "target" |
| 20 | case "rollback": |
| 21 | c.Op.Intent["rollback"] = "other" |
| 22 | case "coverage": |
| 23 | a.Coverage = "clean-return" |
| 24 | case "intent": |
| 25 | r.ConfirmedConsequences.RecoveryIntent = []byte(`{}`) |
| 26 | } |
| 27 | err := MoveLossRecoveryOwner().ValidateLossRecovery(c, r, a) |
| 28 | if (err == nil) != (bad == "") { |
| 29 | t.Fatal(bad, err) |
| 30 | } |
| 31 | } |
| 32 | for _, s := range []string{"replica:ie/gen", "seal:move"} { |
| 33 | if _, _, _, err := ParseMoveLossBaseline(s); err != nil { |
| 34 | t.Fatal(s, err) |
| 35 | } |
| 36 | } |
| 37 | for _, s := range []string{"replica:ie/", "seal:", "replica:ie/gen/other"} { |
| 38 | if _, _, _, err := ParseMoveLossBaseline(s); err == nil { |
| 39 | t.Fatal(s) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |