carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "github.com/carlosframework/platform/internal/hostactors"
5 "github.com/carlosframework/platform/internal/park"
6 "testing"
7)
8
9func TestPlan13ConsoleClaimRegion(t *testing.T) {
10 for _, tc := range []struct {
11 cfg Config
12 code, want string
13 }{
14 {Config{HostClaim: true, HomeRegion: "ie"}, "", "ie"},
15 {Config{HostClaim: true, HomeRegion: "ie"}, "uk", "uk"},
16 {Config{HostClaim: true}, "", park.HomeRegion},
17 {Config{HostClaim: true, HomeRegion: "ie"}, "@home", ""},
18 } {
19 if got := tc.cfg.claimPlacementRegion(tc.code); got != tc.want {
20 t.Fatalf("%+v: %q", tc, got)
21 }
22 }
23 for _, tc := range []struct {
24 cfg Config
25 want string
26 }{
27 {Config{Region: "", HomeRegion: "ie", HibernateRegion: "eu-west-1"}, "ie"},
28 {Config{HibernateRegion: "eu-west-1"}, "eu-west-1"},
29 {Config{HostClaim: true, HomeRegion: "ie", HibernateRegion: "eu-west-1"}, "ie"},
30 {Config{HostClaim: true, Region: "uk", HomeRegion: "ie"}, "uk"},
31 {Config{HostClaim: true, HibernateRegion: "eu-west-1"}, park.HomeRegion},
32 } {
33 if got := tc.cfg.dbClaimRegion(); got != tc.want {
34 t.Fatalf("%+v: %q", tc, got)
35 }
36 }
37}
38
39func TestPlan13ConsoleResolvedHomeAgreement(t *testing.T) {
40 for _, cfg := range []Config{
41 {HostClaim: true, HomeRegion: "ie", HibernateRegion: "eu-west-1", HibernateBucket: "data"},
42 {HostClaim: true, HibernateRegion: "eu-west-1", HibernateBucket: "data"},
43 } {
44 home := cfg.dbClaimHomeRegion()
45 if !(hostactors.Roster{HomeRegion: home}).MatchesHome(home) {
46 t.Fatal(cfg)
47 }
48 if (hostactors.Roster{HomeRegion: "ca"}).MatchesHome(home) {
49 t.Fatal("conflicting console home accepted")
50 }
51 }
52}
53
54func TestPlan13UnnamedHomeMoveNames(t *testing.T) {
55 s := &Server{cfg: Config{HostClaim: true, HibernateRegion: "eu-west-1", HibernateBucket: "data"}}
56 if s.homeRegionOut("") != "eu-west-1" || s.homeRegionIn("eu-west-1") != "" {
57 t.Fatal("move door used a second home binding")
58 }
59 s.cfg.HostClaim = false
60 if s.homeRegionOut("") != "" || s.homeRegionIn("eu-west-1") != "eu-west-1" {
61 t.Fatal("flag-off changed")
62 }
63}
64