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_SourceKindAndKindsConflict(t *testing.T) { cfg := &Config{ Sources: []SourceConfig{ { Name: "src1", Driver: "driver1", Every: Duration{Duration: time.Minute}, Kind: "observation", Kinds: []string{"forecast"}, }, }, 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].kind`) { t.Fatalf("expected error to mention sources[0].kind, 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) } }