| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/registry" |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | "github.com/carlosframework/platform/internal/telemetry" |
| 10 | ) |
| 11 | |
| 12 | func TestTelemetrySwitchesResolvePerRoute(t *testing.T) { |
| 13 | ctx := context.Background() |
| 14 | s := release.NewDirStore(t.TempDir()) |
| 15 | reg := edgesTestRegistry(t) |
| 16 | for _, rt := range []registry.Route{ |
| 17 | {Host: "a.example", Kind: "instance", Account: "bab", App: "web", Status: "ready"}, |
| 18 | {Host: "b.example", Kind: "service", Account: "bab", App: "api", Status: "ready"}, |
| 19 | {Host: "c.example", Kind: "static", Account: "zzz", App: "site", Status: "ready"}, |
| 20 | {Host: "status.example", Kind: "status", Status: "ready"}, |
| 21 | } { |
| 22 | if err := reg.Upsert(rt); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | } |
| 26 | telemetry.Update(ctx, s, telemetry.AccountKey("bab"), func(st *telemetry.Settings) { st.Analytics = &telemetry.Analytics{Count: telemetry.CountEdge} }) |
| 27 | telemetry.Update(ctx, s, telemetry.AppKey("bab", "api"), func(st *telemetry.Settings) { st.Analytics = &telemetry.Analytics{Count: telemetry.CountOff} }) |
| 28 | on, err := telemetrySwitches(ctx, s, reg) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | if !on["bab/web"] || on["bab/api"] || on["zzz/site"] { |
| 33 | t.Fatalf("switches = %v", on) |
| 34 | } |
| 35 | if _, ok := on["/"]; ok { |
| 36 | t.Fatal("status routes have no app and must not appear") |
| 37 | } |
| 38 | } |
| 39 | |