diff --git a/config/config.go b/config/config.go index 8c46740c..b7dac403 100644 --- a/config/config.go +++ b/config/config.go @@ -435,17 +435,17 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { // checkReceiver returns an error if a node in the routing tree // references a receiver not in the given map. func checkReceiver(r *Route, receivers map[string]struct{}) error { + for _, sr := range r.Routes { + if err := checkReceiver(sr, receivers); err != nil { + return err + } + } if r.Receiver == "" { return nil } if _, ok := receivers[r.Receiver]; !ok { return fmt.Errorf("undefined receiver %q used in route", r.Receiver) } - for _, sr := range r.Routes { - if err := checkReceiver(sr, receivers); err != nil { - return err - } - } return nil } diff --git a/config/config_test.go b/config/config_test.go index da43d7ee..94aac38d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -103,6 +103,34 @@ receivers: } +func TestReceiverExistsForDeepSubRoute(t *testing.T) { + in := ` +route: + receiver: team-X + routes: + - match: + foo: bar + routes: + - match: + foo: bar + receiver: nonexistent + +receivers: +- name: 'team-X' +` + _, err := Load(in) + + expected := "undefined receiver \"nonexistent\" used in route" + + if err == nil { + t.Fatalf("no error returned, expected:\n%q", expected) + } + if err.Error() != expected { + t.Errorf("\nexpected:\n%q\ngot:\n%q", expected, err.Error()) + } + +} + func TestReceiverHasName(t *testing.T) { in := ` route: