carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package park
2
3import (
4 "github.com/carlosframework/platform/internal/hostclaim"
5 "testing"
6 "time"
7)
8
9func TestPlan13RegionNames(t *testing.T) {
10 for _, tc := range []struct{ home, region, want string }{
11 {"ie", "ie", ""}, {"ie", "", ""}, {"ie", "uk", "uk"}, {"", "ie", "ie"},
12 } {
13 if got := HomePlacementCode(tc.home, tc.region); got != tc.want {
14 t.Fatalf("%+v: %q", tc, got)
15 }
16 }
17 for _, tc := range []struct {
18 home, a, b string
19 want bool
20 }{
21 {"ie", "ie", HomeRegion, true}, {"ie", HomeRegion, "ie", true}, {"ie", "uk", HomeRegion, false},
22 {"", "ie", HomeRegion, false}, {"ie", "", HomeRegion, false}, {"ie", "", "", false},
23 {"ie", "uk", "uk", true}, {"home", "home", HomeRegion, true},
24 } {
25 if got := SameRegion(tc.home, tc.a, tc.b); got != tc.want {
26 t.Fatalf("%+v: %v", tc, got)
27 }
28 }
29 q := map[string]time.Time{"ie": time.Unix(5, 0), HomeRegion: time.Unix(9, 0), "uk": time.Unix(12, 0)}
30 if !QuietUntil(q, "ie", "ie").Equal(q[HomeRegion]) || !QuietUntil(q, "ie", "uk").Equal(q["uk"]) {
31 t.Fatal("quiet aliases")
32 }
33}
34func TestPlan13OldAdmissionLiveSet(t *testing.T) {
35 c := &hostclaim.Claim{Holder: &hostclaim.Holder{Location: "instances/h/i", Generation: "new", Admissions: []hostclaim.AdmissionRecord{
36 {Generation: "new", Predecessor: "old", Region: "ie", PredecessorRegion: "ie", Mode: "cold"},
37 }}, Op: hostclaim.Op{Kind: hostclaim.KindServing}}
38 v := View{HomeRegion: "ie", Region: HomeRegion, AuthoritativeRegion: HomeRegion, MarkerKnown: true, MarkerGeneration: "old", GenerationOf: func(Ref) (string, bool) { return "old", true }}
39 got, err := LiveGenerations(c, v, c.Holder.Location)
40 if err != nil || !got["old"] || !got["new"] {
41 t.Fatalf("%v %v", got, err)
42 }
43 if c.Holder.Admissions[0].Region != "ie" {
44 t.Fatal("rewrote history")
45 }
46 v.Region = "uk"
47 got, err = LiveGenerations(c, v, c.Holder.Location)
48 if err != nil || len(got) != 0 {
49 t.Fatalf("foreign: %v %v", got, err)
50 }
51}
52