| 1 | //go:build unix |
| 2 | |
| 3 | package hostbox |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "github.com/carlosframework/platform/internal/genselect" |
| 8 | "github.com/carlosframework/platform/internal/hostclaim" |
| 9 | "github.com/carlosframework/platform/internal/park" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | func TestPlan13AdmissionKeepsExistingEngineName(t *testing.T) { |
| 14 | for _, home := range []string{"ie", ""} { |
| 15 | t.Run("home="+home, func(t *testing.T) { |
| 16 | _, store, o := workFixture(t) |
| 17 | writer := Writer{HomeRegion: home, Claims: store, Box: "box", Region: park.PlacementRegion("ie"), AdmissionEvidence: func(context.Context, hostclaim.Observed, hostclaim.Admission, *genselect.Plan) error { return nil }} |
| 18 | in := hostclaim.Admission{Box: "box", Mode: "cold", NewGeneration: "old", Region: "ie", PredecessorRegion: "ie"} |
| 19 | old, err := writer.Admit(t.Context(), o, in, nil) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | // Restart against the stored named admission, rather than a synthesized holder. |
| 24 | old, err = hostclaim.Read(t.Context(), store, o.Host) |
| 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | in.NewGeneration = "next" |
| 29 | in.ObservedSession = old.Claim.Holder.Session |
| 30 | in.ObservedGeneration = "old" |
| 31 | next, err := writer.Admit(t.Context(), old, in, nil) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | a := next.Claim.Holder.Admissions |
| 36 | if len(a) != 2 || a[0].Region != "ie" || a[1].Region != "ie" || a[1].PredecessorRegion != "ie" || a[1].Predecessor != "old" { |
| 37 | t.Fatalf("%+v", a) |
| 38 | } |
| 39 | writer.Region = "" |
| 40 | in.Region = "" |
| 41 | if _, err = writer.Admit(t.Context(), next, in, nil); err == nil { |
| 42 | t.Fatal("unset admitted") |
| 43 | } |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |