| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/hostbox" |
| 8 | "github.com/carlosframework/platform/internal/hostclaim" |
| 9 | "github.com/carlosframework/platform/internal/hostguard" |
| 10 | "github.com/carlosframework/platform/internal/park" |
| 11 | ) |
| 12 | |
| 13 | // Main's IdentityProvider.Local refuses a selection whose home binding is |
| 14 | // not the actor's (HomeRegion and FleetHomeRegion), so the install's one |
| 15 | // Selection carries the work source's binding, as main's own selections do |
| 16 | // (WorkSource.Select, claimAdminTokens, claimLaunchAuthority). |
| 17 | func TestRelocationInstallSelectionCarriesTheHomeBinding(t *testing.T) { |
| 18 | var got hostbox.Selection |
| 19 | src := hostbox.WorkSource{HomeRegion: "ie", FleetHomeRegion: "ie", Box: "dst", Region: "ie", |
| 20 | Local: func(_ context.Context, _ *hostclaim.Claim, s hostbox.Selection) error { got = s; return nil }} |
| 21 | c := &hostclaim.Claim{Host: "shop.example", Op: hostclaim.Op{Kind: hostclaim.KindRelocating, ID: "rel-1", Phase: hostclaim.PhaseInstalling}, |
| 22 | Holder: &hostclaim.Holder{Generation: "g1", Session: 2}} |
| 23 | if err := relocationInstallLocal(t.Context(), src, c, hostguard.Captured{Incarnation: "inc", Stamp: 4}); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | if got.HomeRegion != "ie" || got.FleetHomeRegion != "ie" || got.Region != "ie" || got.Box != "dst" || got.Action != relocationActionInstall { |
| 27 | t.Fatalf("selection %+v", got) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // The relocation wake's generation selection and its fresh publisher see |
| 32 | // the holder through the box's home binding (park.HolderRegionView), as |
| 33 | // main's serving owners do: an admission moves recorded under |
| 34 | // park.HomeRegion is this region's. |
| 35 | func TestRelocationWakeSelectsThroughTheHomeBinding(t *testing.T) { |
| 36 | o := hostclaim.Observed{Host: "shop.example", Claim: &hostclaim.Claim{Holder: &hostclaim.Holder{ |
| 37 | Admissions: []hostclaim.AdmissionRecord{{Region: park.HomeRegion, PredecessorRegion: "uk", Generation: "g1"}}}}} |
| 38 | for _, tc := range []struct{ home, want string }{{"ie", "ie"}, {"", park.HomeRegion}} { |
| 39 | r := &RelocationWakeInputs{Bucket: "data", Region: "ie", HomeRegion: tc.home} |
| 40 | req := r.request(o) |
| 41 | if req.Region != "ie" || req.Holder.Admissions[0].Region != tc.want || req.Holder.Admissions[0].PredecessorRegion != "uk" { |
| 42 | t.Fatalf("home %q: request %+v", tc.home, req) |
| 43 | } |
| 44 | if f := r.freshOwners(); f.HomeRegion != tc.home || f.Region != "ie" { |
| 45 | t.Fatalf("home %q: fresh owners %+v", tc.home, f) |
| 46 | } |
| 47 | } |
| 48 | if o.Claim.Holder.Admissions[0].Region != park.HomeRegion { |
| 49 | t.Fatal("the view changed the claim's own holder") |
| 50 | } |
| 51 | } |
| 52 | |