package park import ( "errors" "testing" "github.com/carlosframework/platform/internal/hostclaim" ) // TestLiveGenerationsWalksTheUnfinishedChain: the exported live set is the // engine's own: with the marker lagging at g1 and the holder at g3, the // unfinished cold chain g3 -> g2 -> g1 in the authoritative region is live; // a region that is not authoritative has none; a missing claim refuses. func TestLiveGenerationsWalksTheUnfinishedChain(t *testing.T) { loc := "instances/h.example" c := &hostclaim.Claim{Host: "h.example", Op: hostclaim.Op{Kind: hostclaim.KindServing}, Holder: &hostclaim.Holder{Location: loc, Generation: "g3", Admissions: []hostclaim.AdmissionRecord{ {Generation: "g1", Mode: "cold", Region: "ie"}, {Generation: "g2", Predecessor: "g1", Mode: "cold", Region: "ie", PredecessorRegion: "ie"}, {Generation: "g3", Predecessor: "g2", Mode: "cold", Region: "ie", PredecessorRegion: "ie"}, }}} v := View{Region: "ie", AuthoritativeRegion: "ie", MarkerKnown: true, MarkerGeneration: "g1", GenerationOf: func(Ref) (string, bool) { return "", true }} live, err := LiveGenerations(c, v, loc) if err != nil { t.Fatal(err) } for _, g := range []string{"g1", "g2", "g3"} { if !live[g] { t.Fatalf("live %v, missing %s", live, g) } } v.Region = "uk" if live, err := LiveGenerations(c, v, loc); err != nil || len(live) != 0 { t.Fatalf("a non-authoritative region: %v %v", live, err) } if _, err := LiveGenerations(nil, v, loc); !errors.Is(err, ErrUnsafe) { t.Fatalf("no claim: %v", err) } }