| 1 | package park |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/hostclaim" |
| 8 | ) |
| 9 | |
| 10 | // TestLiveGenerationsWalksTheUnfinishedChain: the exported live set is the |
| 11 | // engine's own: with the marker lagging at g1 and the holder at g3, the |
| 12 | // unfinished cold chain g3 -> g2 -> g1 in the authoritative region is live; |
| 13 | // a region that is not authoritative has none; a missing claim refuses. |
| 14 | func TestLiveGenerationsWalksTheUnfinishedChain(t *testing.T) { |
| 15 | loc := "instances/h.example" |
| 16 | c := &hostclaim.Claim{Host: "h.example", Op: hostclaim.Op{Kind: hostclaim.KindServing}, Holder: &hostclaim.Holder{Location: loc, Generation: "g3", |
| 17 | Admissions: []hostclaim.AdmissionRecord{ |
| 18 | {Generation: "g1", Mode: "cold", Region: "ie"}, |
| 19 | {Generation: "g2", Predecessor: "g1", Mode: "cold", Region: "ie", PredecessorRegion: "ie"}, |
| 20 | {Generation: "g3", Predecessor: "g2", Mode: "cold", Region: "ie", PredecessorRegion: "ie"}, |
| 21 | }}} |
| 22 | v := View{Region: "ie", AuthoritativeRegion: "ie", MarkerKnown: true, MarkerGeneration: "g1", GenerationOf: func(Ref) (string, bool) { return "", true }} |
| 23 | live, err := LiveGenerations(c, v, loc) |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | for _, g := range []string{"g1", "g2", "g3"} { |
| 28 | if !live[g] { |
| 29 | t.Fatalf("live %v, missing %s", live, g) |
| 30 | } |
| 31 | } |
| 32 | v.Region = "uk" |
| 33 | if live, err := LiveGenerations(c, v, loc); err != nil || len(live) != 0 { |
| 34 | t.Fatalf("a non-authoritative region: %v %v", live, err) |
| 35 | } |
| 36 | if _, err := LiveGenerations(nil, v, loc); !errors.Is(err, ErrUnsafe) { |
| 37 | t.Fatalf("no claim: %v", err) |
| 38 | } |
| 39 | } |
| 40 | |