68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
|
|
package dispatch
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"gitea.maximumdirect.net/ejr/feedkit/config"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestCompileRoutes_DefaultIsAllSinksAllKinds(t *testing.T) {
|
||
|
|
cfg := &config.Config{
|
||
|
|
Sinks: []config.SinkConfig{
|
||
|
|
{Name: "a", Driver: "stdout"},
|
||
|
|
{Name: "b", Driver: "stdout"},
|
||
|
|
},
|
||
|
|
// Routes omitted => default
|
||
|
|
}
|
||
|
|
|
||
|
|
routes, err := CompileRoutes(cfg)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("CompileRoutes error: %v", err)
|
||
|
|
}
|
||
|
|
if len(routes) != 2 {
|
||
|
|
t.Fatalf("expected 2 routes, got %d", len(routes))
|
||
|
|
}
|
||
|
|
|
||
|
|
// Order should match cfg.Sinks order (deterministic).
|
||
|
|
if routes[0].SinkName != "a" || routes[1].SinkName != "b" {
|
||
|
|
t.Fatalf("unexpected route order: %+v", routes)
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, r := range routes {
|
||
|
|
if len(r.Kinds) != 0 {
|
||
|
|
t.Fatalf("expected nil/empty kinds for default routes, got: %+v", r.Kinds)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestCompileRoutes_EmptyKindsMeansAllKinds(t *testing.T) {
|
||
|
|
cfg := &config.Config{
|
||
|
|
Sinks: []config.SinkConfig{
|
||
|
|
{Name: "sink1", Driver: "stdout"},
|
||
|
|
},
|
||
|
|
Routes: []config.RouteConfig{
|
||
|
|
{Sink: "sink1"}, // omitted kinds
|
||
|
|
{Sink: "sink1", Kinds: nil}, // explicit nil
|
||
|
|
{Sink: "sink1", Kinds: []string{}}, // explicit empty
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
routes, err := CompileRoutes(cfg)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("CompileRoutes error: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(routes) != 3 {
|
||
|
|
t.Fatalf("expected 3 routes, got %d", len(routes))
|
||
|
|
}
|
||
|
|
|
||
|
|
for i, r := range routes {
|
||
|
|
if r.SinkName != "sink1" {
|
||
|
|
t.Fatalf("route[%d] unexpected sink: %q", i, r.SinkName)
|
||
|
|
}
|
||
|
|
if len(r.Kinds) != 0 {
|
||
|
|
t.Fatalf("route[%d] expected nil/empty kinds (match all), got: %+v", i, r.Kinds)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|