MCPcopy
hub / github.com/nats-io/nats.go / TestErrHandlerSubjectMatch

Function TestErrHandlerSubjectMatch

micro/test/service_test.go:558–657  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

556}
557
558func TestErrHandlerSubjectMatch(t *testing.T) {
559 tests := []struct {
560 name string
561 endpointSubject string
562 errSubject string
563 expectServiceErr bool
564 }{
565 {
566 name: "exact match",
567 endpointSubject: "foo.bar.baz",
568 errSubject: "foo.bar.baz",
569 expectServiceErr: true,
570 },
571 {
572 name: "match with *",
573 endpointSubject: "foo.*.baz",
574 errSubject: "foo.bar.baz",
575 expectServiceErr: true,
576 },
577 {
578 name: "match with >",
579 endpointSubject: "foo.bar.>",
580 errSubject: "foo.bar.baz.1",
581 expectServiceErr: true,
582 },
583 {
584 name: "monitoring handler",
585 endpointSubject: "foo.bar.>",
586 errSubject: "$SRV.PING",
587 expectServiceErr: true,
588 },
589 {
590 name: "endpoint longer than subject",
591 endpointSubject: "foo.bar.baz",
592 errSubject: "foo.bar",
593 expectServiceErr: false,
594 },
595 {
596 name: "no match",
597 endpointSubject: "foo.bar.baz",
598 errSubject: "foo.baz.bar",
599 expectServiceErr: false,
600 },
601 {
602 name: "no match with *",
603 endpointSubject: "foo.*.baz",
604 errSubject: "foo.bar.foo",
605 expectServiceErr: false,
606 },
607 }
608
609 for _, test := range tests {
610 t.Run(test.name, func(t *testing.T) {
611 coreNatsAsyncErrors := []nats.ErrHandler{nil, func(c *nats.Conn, s *nats.Subscription, err error) {}}
612 for _, cb := range coreNatsAsyncErrors {
613 errChan := make(chan struct{})
614 errHandler := func(s micro.Service, err *micro.NATSError) {
615 errChan <- struct{}{}

Callers

nothing calls this directly

Calls 9

AddServiceFunction · 0.92
ErrHandlerFuncType · 0.92
HandlerFuncFuncType · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
SetErrorHandlerMethod · 0.80
RunServerOnPortFunction · 0.70
StopMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected