package console import ( "github.com/carlosframework/platform/internal/hostactors" "github.com/carlosframework/platform/internal/park" "testing" ) func TestPlan13ConsoleClaimRegion(t *testing.T) { for _, tc := range []struct { cfg Config code, want string }{ {Config{HostClaim: true, HomeRegion: "ie"}, "", "ie"}, {Config{HostClaim: true, HomeRegion: "ie"}, "uk", "uk"}, {Config{HostClaim: true}, "", park.HomeRegion}, {Config{HostClaim: true, HomeRegion: "ie"}, "@home", ""}, } { if got := tc.cfg.claimPlacementRegion(tc.code); got != tc.want { t.Fatalf("%+v: %q", tc, got) } } for _, tc := range []struct { cfg Config want string }{ {Config{Region: "", HomeRegion: "ie", HibernateRegion: "eu-west-1"}, "ie"}, {Config{HibernateRegion: "eu-west-1"}, "eu-west-1"}, {Config{HostClaim: true, HomeRegion: "ie", HibernateRegion: "eu-west-1"}, "ie"}, {Config{HostClaim: true, Region: "uk", HomeRegion: "ie"}, "uk"}, {Config{HostClaim: true, HibernateRegion: "eu-west-1"}, park.HomeRegion}, } { if got := tc.cfg.dbClaimRegion(); got != tc.want { t.Fatalf("%+v: %q", tc, got) } } } func TestPlan13ConsoleResolvedHomeAgreement(t *testing.T) { for _, cfg := range []Config{ {HostClaim: true, HomeRegion: "ie", HibernateRegion: "eu-west-1", HibernateBucket: "data"}, {HostClaim: true, HibernateRegion: "eu-west-1", HibernateBucket: "data"}, } { home := cfg.dbClaimHomeRegion() if !(hostactors.Roster{HomeRegion: home}).MatchesHome(home) { t.Fatal(cfg) } if (hostactors.Roster{HomeRegion: "ca"}).MatchesHome(home) { t.Fatal("conflicting console home accepted") } } } func TestPlan13UnnamedHomeMoveNames(t *testing.T) { s := &Server{cfg: Config{HostClaim: true, HibernateRegion: "eu-west-1", HibernateBucket: "data"}} if s.homeRegionOut("") != "eu-west-1" || s.homeRegionIn("eu-west-1") != "" { t.Fatal("move door used a second home binding") } s.cfg.HostClaim = false if s.homeRegionOut("") != "" || s.homeRegionIn("eu-west-1") != "eu-west-1" { t.Fatal("flag-off changed") } }