Remove global Postgres schema registration in favor of explicit schema-aware sink factory wiring, and update weatherfeeder to register the Postgres sink explicitly. Add optional per-source HTTP timeout and response body limit overrides while keeping feedkit defaults. Remove remaining legacy source/config compatibility surfaces, including singular kind support and old source registry/type aliases, and migrate weatherfeeder sources to plural `Kinds()` metadata. Clean up related docs, tests, and sample config to match the new Postgres, HTTP, and NATS configuration model.
140 lines
3.1 KiB
Go
140 lines
3.1 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestValidate_RouteKindsEmptyIsAllowed(t *testing.T) {
|
|
cfg := &Config{
|
|
Sources: []SourceConfig{
|
|
{Name: "src1", Driver: "driver1", Every: Duration{Duration: time.Minute}},
|
|
},
|
|
Sinks: []SinkConfig{
|
|
{Name: "sink1", Driver: "stdout"},
|
|
},
|
|
Routes: []RouteConfig{
|
|
{Sink: "sink1", Kinds: nil}, // omitted
|
|
{Sink: "sink1", Kinds: []string{}}, // explicit empty
|
|
},
|
|
}
|
|
|
|
if err := cfg.Validate(); err != nil {
|
|
t.Fatalf("expected no error, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidate_RouteKindsRejectsBlankEntries(t *testing.T) {
|
|
cfg := &Config{
|
|
Sources: []SourceConfig{
|
|
{Name: "src1", Driver: "driver1", Every: Duration{Duration: time.Minute}},
|
|
},
|
|
Sinks: []SinkConfig{
|
|
{Name: "sink1", Driver: "stdout"},
|
|
},
|
|
Routes: []RouteConfig{
|
|
{Sink: "sink1", Kinds: []string{"observation", " ", "alert"}},
|
|
},
|
|
}
|
|
|
|
err := cfg.Validate()
|
|
if err == nil {
|
|
t.Fatalf("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), "routes[0].kinds[1]") {
|
|
t.Fatalf("expected error to mention blank kind entry, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidate_SourceModePollRequiresEvery(t *testing.T) {
|
|
cfg := &Config{
|
|
Sources: []SourceConfig{
|
|
{Name: "src1", Driver: "driver1", Mode: SourceModePoll},
|
|
},
|
|
Sinks: []SinkConfig{
|
|
{Name: "sink1", Driver: "stdout"},
|
|
},
|
|
}
|
|
|
|
err := cfg.Validate()
|
|
if err == nil {
|
|
t.Fatalf("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `sources[0].every`) {
|
|
t.Fatalf("expected error to mention sources[0].every, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidate_SourceModeStreamRejectsEvery(t *testing.T) {
|
|
cfg := &Config{
|
|
Sources: []SourceConfig{
|
|
{
|
|
Name: "src1",
|
|
Driver: "driver1",
|
|
Mode: SourceModeStream,
|
|
Every: Duration{Duration: time.Minute},
|
|
},
|
|
},
|
|
Sinks: []SinkConfig{
|
|
{Name: "sink1", Driver: "stdout"},
|
|
},
|
|
}
|
|
|
|
err := cfg.Validate()
|
|
if err == nil {
|
|
t.Fatalf("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `sources[0].every`) {
|
|
t.Fatalf("expected error to mention sources[0].every, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidate_SourceModeRejectsUnknownValue(t *testing.T) {
|
|
cfg := &Config{
|
|
Sources: []SourceConfig{
|
|
{
|
|
Name: "src1",
|
|
Driver: "driver1",
|
|
Mode: SourceMode("batch"),
|
|
Every: Duration{Duration: time.Minute},
|
|
},
|
|
},
|
|
Sinks: []SinkConfig{
|
|
{Name: "sink1", Driver: "stdout"},
|
|
},
|
|
}
|
|
|
|
err := cfg.Validate()
|
|
if err == nil {
|
|
t.Fatalf("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `sources[0].mode`) {
|
|
t.Fatalf("expected error to mention sources[0].mode, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidate_SourceKindsRejectBlankEntries(t *testing.T) {
|
|
cfg := &Config{
|
|
Sources: []SourceConfig{
|
|
{
|
|
Name: "src1",
|
|
Driver: "driver1",
|
|
Every: Duration{Duration: time.Minute},
|
|
Kinds: []string{"observation", " "},
|
|
},
|
|
},
|
|
Sinks: []SinkConfig{
|
|
{Name: "sink1", Driver: "stdout"},
|
|
},
|
|
}
|
|
|
|
err := cfg.Validate()
|
|
if err == nil {
|
|
t.Fatalf("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `sources[0].kinds[1]`) {
|
|
t.Fatalf("expected error to mention sources[0].kinds[1], got: %v", err)
|
|
}
|
|
}
|