| 1 | package hostops |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "github.com/carlosframework/platform/internal/hostclaim" |
| 7 | "github.com/carlosframework/platform/internal/park" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestPlan13RemoteAdapterUsesBoundHome(t *testing.T) { |
| 12 | f := newMoveStartFixture(t, nil) |
| 13 | o := f.read(t) |
| 14 | _, err := hostclaim.Update(t.Context(), f.raw, o, func(c *hostclaim.Claim) error { |
| 15 | c.Obligations = []hostclaim.Obligation{{ID: "chore", Op: "old", Kind: "park-replica", Region: "@home", Owner: "region:@home", Retirement: "ret"}} |
| 16 | return nil |
| 17 | }) |
| 18 | if err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | sentinel := errors.New("scope reached") |
| 22 | for _, home := range []string{"ie", ""} { |
| 23 | e := park.Engine{Claims: f.raw, Region: "ie", HomeRegion: home, Leases: plan13NoLeases{}, Authorize: func(context.Context, hostclaim.Observed, hostclaim.Obligation) error { return nil }, View: func(context.Context, hostclaim.Observed) (park.View, error) { return park.View{}, nil }} |
| 24 | err := RunOwnedRemote(t.Context(), &e, park.Work{Host: f.host, ID: "chore", Op: "old"}, func(context.Context, hostclaim.Observed, hostclaim.Obligation) (hostclaim.ParkScope, error) { |
| 25 | return hostclaim.ParkScope{}, sentinel |
| 26 | }) |
| 27 | if errors.Is(err, sentinel) != (home != "") { |
| 28 | t.Fatal(home, err) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | type plan13NoLeases struct{} |
| 34 | |
| 35 | func (plan13NoLeases) Acquire(context.Context, string, string) (park.HeldLease, error) { |
| 36 | return nil, errors.New("unexpected lease") |
| 37 | } |
| 38 | |