carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package activator
2
3import (
4 "context"
5 "testing"
6
7 "github.com/carlosframework/platform/internal/registry"
8)
9
10// seedPlacingBackend is a fakeBackend that records SeedPlaced calls.
11type seedPlacingBackend struct {
12 *fakeBackend
13 placed []string
14 rep Rep
15}
16
17func (b *seedPlacingBackend) SeedPlaced(_ context.Context, rt registry.Route, rep Rep) error {
18 b.placed = append(b.placed, rt.Host)
19 b.rep = rep
20 return nil
21}
22
23type noSyncRep struct{}
24
25func (noSyncRep) Err() error { return nil }
26func (noSyncRep) Close(context.Context) error { return nil }
27
28// SplitBackend.SeedPlaced dispatches on Backing: an exec route reaches the
29// exec backend's SeedPlaced with the same Rep; a unit route is never
30// forwarded and answers nil.
31func TestSplitBackendSeedPlacedDispatchesByBacking(t *testing.T) {
32 eb := &seedPlacingBackend{fakeBackend: &fakeBackend{}}
33 sb := &SplitBackend{Exec: eb, Unit: &UnitBackend{OptDir: t.TempDir()}}
34 ctx := context.Background()
35 rep := noSyncRep{}
36
37 if err := sb.SeedPlaced(ctx, testUnitRoute("unit.example.com"), rep); err != nil {
38 t.Fatalf("unit route: %v", err)
39 }
40 if len(eb.placed) != 0 {
41 t.Fatalf("a unit route reached the exec backend: %q", eb.placed)
42 }
43 if err := sb.SeedPlaced(ctx, testRoute("shop-1.example.com"), rep); err != nil {
44 t.Fatalf("exec route: %v", err)
45 }
46 if len(eb.placed) != 1 || eb.placed[0] != "shop-1.example.com" || eb.rep != Rep(rep) {
47 t.Fatalf("exec route forwarded %q with rep %v", eb.placed, eb.rep)
48 }
49}
50