package host import ( "errors" "testing" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/park" "github.com/carlosframework/platform/internal/provision" ) // TestMovesBoxRegionIsThePlacements: the park view's region is this box's // as the claim knows it, and it must be the engine region of this box's own // placement code. A home box whose claim names home any other way (the // roster's region, a named code, the unset region) refuses rather than // reading a home record from a region that is not HomeRegion. func TestMovesBoxRegionIsThePlacements(t *testing.T) { for _, tc := range []struct { placement, claims string ok bool }{ {"", park.HomeRegion, true}, {"uk", "uk", true}, {"", "ie", false}, {"", "", false}, {"uk", "ie", false}, {"uk", park.HomeRegion, false}, {"IE", "IE", false}, {park.HomeRegion, park.HomeRegion, false}, } { f := newVwFixture(t) f.rec.Region = "" f.rec.Move = &provision.MoveState{ID: vwMove, Incarnation: f.inc, From: "", To: "uk", State: provision.MoveCutting} obs := vwObs(&hostclaim.Claim{Holder: f.holder(""), Op: hostclaim.Op{Kind: hostclaim.KindMoving, ID: vwMove, Phase: hostclaim.PhaseMoving, Exec: "box"}}) v, err := movesParkViewAt(f.records(), f.bucket, "data", movesBoxRegion(tc.placement, fixedRegion(tc.claims)))(t.Context(), obs) if tc.ok != (err == nil) { t.Fatalf("placement %q, claim region %q: view %+v, %v", tc.placement, tc.claims, v, err) } if tc.ok && v.Region != tc.claims { t.Fatalf("placement %q: the view's region %q", tc.placement, v.Region) } if !tc.ok && !errors.Is(err, park.ErrUnsafe) { t.Fatalf("placement %q, claim region %q: %v, want ErrUnsafe", tc.placement, tc.claims, err) } } }