package host import ( "context" "testing" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/hostguard" "github.com/carlosframework/platform/internal/park" ) // Main's IdentityProvider.Local refuses a selection whose home binding is // not the actor's (HomeRegion and FleetHomeRegion), so the install's one // Selection carries the work source's binding, as main's own selections do // (WorkSource.Select, claimAdminTokens, claimLaunchAuthority). func TestRelocationInstallSelectionCarriesTheHomeBinding(t *testing.T) { var got hostbox.Selection src := hostbox.WorkSource{HomeRegion: "ie", FleetHomeRegion: "ie", Box: "dst", Region: "ie", Local: func(_ context.Context, _ *hostclaim.Claim, s hostbox.Selection) error { got = s; return nil }} c := &hostclaim.Claim{Host: "shop.example", Op: hostclaim.Op{Kind: hostclaim.KindRelocating, ID: "rel-1", Phase: hostclaim.PhaseInstalling}, Holder: &hostclaim.Holder{Generation: "g1", Session: 2}} if err := relocationInstallLocal(t.Context(), src, c, hostguard.Captured{Incarnation: "inc", Stamp: 4}); err != nil { t.Fatal(err) } if got.HomeRegion != "ie" || got.FleetHomeRegion != "ie" || got.Region != "ie" || got.Box != "dst" || got.Action != relocationActionInstall { t.Fatalf("selection %+v", got) } } // The relocation wake's generation selection and its fresh publisher see // the holder through the box's home binding (park.HolderRegionView), as // main's serving owners do: an admission moves recorded under // park.HomeRegion is this region's. func TestRelocationWakeSelectsThroughTheHomeBinding(t *testing.T) { o := hostclaim.Observed{Host: "shop.example", Claim: &hostclaim.Claim{Holder: &hostclaim.Holder{ Admissions: []hostclaim.AdmissionRecord{{Region: park.HomeRegion, PredecessorRegion: "uk", Generation: "g1"}}}}} for _, tc := range []struct{ home, want string }{{"ie", "ie"}, {"", park.HomeRegion}} { r := &RelocationWakeInputs{Bucket: "data", Region: "ie", HomeRegion: tc.home} req := r.request(o) if req.Region != "ie" || req.Holder.Admissions[0].Region != tc.want || req.Holder.Admissions[0].PredecessorRegion != "uk" { t.Fatalf("home %q: request %+v", tc.home, req) } if f := r.freshOwners(); f.HomeRegion != tc.home || f.Region != "ie" { t.Fatalf("home %q: fresh owners %+v", tc.home, f) } } if o.Claim.Holder.Admissions[0].Region != park.HomeRegion { t.Fatal("the view changed the claim's own holder") } }