carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "errors"
5 "testing"
6
7 "github.com/carlosframework/platform/internal/hostclaim"
8 "github.com/carlosframework/platform/internal/park"
9 "github.com/carlosframework/platform/internal/provision"
10)
11
12// TestMovesBoxRegionIsThePlacements: the park view's region is this box's
13// as the claim knows it, and it must be the engine region of this box's own
14// placement code. A home box whose claim names home any other way (the
15// roster's region, a named code, the unset region) refuses rather than
16// reading a home record from a region that is not HomeRegion.
17func TestMovesBoxRegionIsThePlacements(t *testing.T) {
18 for _, tc := range []struct {
19 placement, claims string
20 ok bool
21 }{
22 {"", park.HomeRegion, true},
23 {"uk", "uk", true},
24 {"", "ie", false},
25 {"", "", false},
26 {"uk", "ie", false},
27 {"uk", park.HomeRegion, false},
28 {"IE", "IE", false},
29 {park.HomeRegion, park.HomeRegion, false},
30 } {
31 f := newVwFixture(t)
32 f.rec.Region = ""
33 f.rec.Move = &provision.MoveState{ID: vwMove, Incarnation: f.inc, From: "", To: "uk", State: provision.MoveCutting}
34 obs := vwObs(&hostclaim.Claim{Holder: f.holder(""), Op: hostclaim.Op{Kind: hostclaim.KindMoving, ID: vwMove, Phase: hostclaim.PhaseMoving, Exec: "box"}})
35 v, err := movesParkViewAt(f.records(), f.bucket, "data", movesBoxRegion(tc.placement, fixedRegion(tc.claims)))(t.Context(), obs)
36 if tc.ok != (err == nil) {
37 t.Fatalf("placement %q, claim region %q: view %+v, %v", tc.placement, tc.claims, v, err)
38 }
39 if tc.ok && v.Region != tc.claims {
40 t.Fatalf("placement %q: the view's region %q", tc.placement, v.Region)
41 }
42 if !tc.ok && !errors.Is(err, park.ErrUnsafe) {
43 t.Fatalf("placement %q, claim region %q: %v, want ErrUnsafe", tc.placement, tc.claims, err)
44 }
45 }
46}
47