carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package hostclaim
2
3import (
4 "context"
5 "fmt"
6 "testing"
7 "time"
8
9 "github.com/carlosframework/platform/internal/release"
10)
11
12func TestSingleOwnerAdoptionDiscoveryBoundary(t *testing.T) {
13 for _, extraRegion := range []bool{false, true} {
14 t.Run(fmt.Sprint(extraRegion), func(t *testing.T) {
15 store := release.NewDirStore(t.TempDir())
16 host := "single.example"
17 nh := NewHolder{Family: "instance", Key: "apps/acct/app/instances/" + host + ".json", Account: "acct", App: "app", Host: host, CreatedAt: time.Date(2026, 10, 7, 0, 0, 0, 0, time.UTC), Region: "ie"}
18 var otherRegions []string
19 if extraRegion {
20 otherRegions = []string{"us"}
21 }
22 seq := 0
23 obs, err := Update(context.Background(), store, Observed{Host: host, Absent: true}, Adopt(nh, "only-box", otherRegions, nil, "discovery", func() string { seq++; return fmt.Sprintf("id%d", seq) }))
24 if err != nil {
25 t.Fatal(err)
26 }
27 if !extraRegion {
28 if !obs.Claim.Touched.Complete || len(obs.Claim.Obligations) != 0 || obs.Claim.Touched.DiscoveryOp != "" {
29 t.Fatalf("single-region adoption needs no evidence: %+v", obs.Claim)
30 }
31 } else {
32 if obs.Claim.Touched.Complete || len(obs.Claim.Obligations) != 1 || obs.Claim.Obligations[0].Region != "us" {
33 t.Fatalf("retirement region was omitted: %+v", obs.Claim)
34 }
35 }
36 })
37 }
38}
39