carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostops
2
3import (
4 "context"
5 "github.com/carlosframework/platform/internal/hostclaim"
6 "github.com/carlosframework/platform/internal/park"
7 "github.com/carlosframework/platform/internal/provision"
8 "testing"
9)
10
11func TestPlan13PreFlipHomeConversion(t *testing.T) {
12 for _, direction := range []string{"source-home", "target-home", "named"} {
13 for _, route := range []string{"grant", "held"} {
14 t.Run(direction+"/"+route, func(t *testing.T) {
15 w := newC7World(t, func(c *hostclaim.Claim, r *provision.Record, _ *AppAdmission) {
16 if direction == "source-home" {
17 r.Region, r.Move.From = "", ""
18 c.Op.Intent["home_region"] = "ie"
19 }
20 if direction == "target-home" {
21 r.Move.To = ""
22 c.Op.Intent["to"] = park.HomeRegion
23 c.Op.Intent["home_region"] = "uk"
24 }
25 })
26 if direction == "source-home" {
27 w.control.homeRegion = "ie"
28 }
29 if direction == "target-home" {
30 w.control.homeRegion = "uk"
31 }
32 run := func() error {
33 if route == "held" {
34 return RecoverTerminatedMovingHost(t.Context(), w.productionData(t, w.raw), w.mh, w.authority, w.host, w.ref, w.now)
35 }
36 return w.control.RunRecovery(t.Context(), func(ctx context.Context) error {
37 return runMoveRecovery(ctx, w.claim(t), func(ctx context.Context, g *MoveRecoveryGrant) error { return g.Convert(ctx, w.ref) }, w.authority)
38 })
39 }
40 for i := 0; i < 3; i++ {
41 if err := run(); err != nil {
42 t.Fatalf("pass %d: %v", i, err)
43 }
44 }
45 c := w.claim(t).Claim
46 if c.Op.Kind != hostclaim.KindRelocating || c.Op.Intent["region"] != "ie" {
47 t.Fatalf("claim: %+v", c.Op)
48 }
49 r, err := provision.GetRecord(t.Context(), w.raw, "bab", "app", w.host)
50 if err != nil {
51 t.Fatal(err)
52 }
53 from, to := "ie", "uk"
54 if direction == "source-home" {
55 from = ""
56 }
57 if direction == "target-home" {
58 to = ""
59 }
60 if r.Region != from || r.Move.From != from || r.Move.To != to || r.Move.Relocation.Region != from {
61 t.Fatalf("rewritten record: %+v", r)
62 }
63 tag := w.claim(t).ETag
64 rtag := w.recordTag(t)
65 if err := run(); err != nil {
66 t.Fatal(err)
67 }
68 if tag != w.claim(t).ETag || rtag != w.recordTag(t) {
69 t.Fatal("replay wrote")
70 }
71 })
72 }
73 }
74}
75func TestPlan13PreFlipUnboundHomeRefuses(t *testing.T) {
76 w := newC7World(t, func(c *hostclaim.Claim, r *provision.Record, _ *AppAdmission) { r.Region, r.Move.From = "", "" })
77 tag := w.recordTag(t)
78 if err := RecoverTerminatedMovingHost(t.Context(), w.productionData(t, w.raw), w.mh, w.authority, w.host, w.ref, w.now); err == nil {
79 t.Fatal("unbound home accepted")
80 }
81 if tag != w.recordTag(t) {
82 t.Fatal("refusal wrote")
83 }
84}
85