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 "testing"
5 "time"
6
7 "github.com/carlosframework/platform/internal/hostclaim"
8 "github.com/carlosframework/platform/internal/release"
9)
10
11// ClaimOriginProof is the moves provider's proof (movesOriginProof's batch
12// contract), adopted with the Plan 15 switch.
13var _ movesOriginProof = ClaimOriginProof{}
14
15func TestPlan15MovesProof(t *testing.T) {
16 t.Setenv("CARLOS_HOST_CLAIM", "1")
17 t.Setenv("CARLOS_HOST_CLAIM_ORIGINS", "1")
18 s := release.NewDirStore(t.TempDir())
19 host := "test.example"
20 o, err := hostclaim.Read(t.Context(), s, host)
21 if err != nil {
22 t.Fatal(err)
23 }
24 n := hostclaim.NewHolder{Family: "instance", Key: "apps/bab/app/instances/test.example.json", Account: "bab", App: "app", Host: host, Region: "ie", CreatedAt: time.Date(2026, 10, 12, 0, 0, 0, 0, time.UTC)}
25 o, err = hostclaim.Update(t.Context(), s, o, hostclaim.BeginCreate(n, []byte(`{"host":"test.example","account":"bab","app":"app","created_at":"2026-10-12T00:00:00Z"}`), "create", "console", time.Now()))
26 if err != nil {
27 t.Fatal(err)
28 }
29 o, err = hostclaim.Update(t.Context(), s, o, hostclaim.CompleteCreate("create", "box"))
30 if err != nil {
31 t.Fatal(err)
32 }
33 o, err = hostclaim.Update(t.Context(), s, o, hostclaim.AdmitWriter(hostclaim.Admission{Box: "box", Mode: "cold", Region: "ie", NewGeneration: "admitted"}))
34 if err != nil {
35 t.Fatal(err)
36 }
37 for _, tc := range []struct {
38 home, region, generation string
39 want bool
40 }{
41 {"", "ie", "admitted", true}, {"ie", "@home", "admitted", true}, {"", "@home", "admitted", false},
42 {"ie", "uk", "admitted", false}, {"", "ie", "prepared", false},
43 } {
44 p := ClaimOriginProof{Claims: s, HomeRegion: tc.home, Region: tc.region}
45 got, err := p.Proven(t.Context(), o, hostclaim.Admission{NewGeneration: tc.generation}, []string{tc.generation})
46 if got[tc.generation] != tc.want || err != nil {
47 t.Fatalf("%+v: %v %v", tc, got, err)
48 }
49 }
50}
51