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

Function TestMonitoringHandlers

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

Source from the content-addressed store, hash-verified

762}
763
764func TestMonitoringHandlers(t *testing.T) {
765 s := RunServerOnPort(-1)
766 defer s.Shutdown()
767
768 nc, err := nats.Connect(s.ClientURL())
769 if err != nil {
770 t.Fatalf("Expected to connect to server, got %v", err)
771 }
772 defer nc.Close()
773
774 asyncErr := make(chan struct{})
775 errHandler := func(s micro.Service, n *micro.NATSError) {
776 asyncErr <- struct{}{}
777 }
778
779 config := micro.Config{
780 Name: "test_service",
781 Version: "0.1.0",
782 ErrorHandler: errHandler,
783 Endpoint: &micro.EndpointConfig{
784 Subject: "test.func",
785 Handler: micro.HandlerFunc(func(r micro.Request) {}),
786 Metadata: map[string]string{"basic": "schema"},
787 },
788 }
789 srv, err := micro.AddService(nc, config)
790 if err != nil {
791 t.Fatalf("Unexpected error: %v", err)
792 }
793 defer func() {
794 srv.Stop()
795 if !srv.Stopped() {
796 t.Fatalf("Expected service to be stopped")
797 }
798 }()
799
800 info := srv.Info()
801
802 tests := []struct {
803 name string
804 subject string
805 withError bool
806 expectedResponse any
807 }{
808 {
809 name: "PING all",
810 subject: "$SRV.PING",
811 expectedResponse: micro.Ping{
812 Type: micro.PingResponseType,
813 ServiceIdentity: micro.ServiceIdentity{
814 Name: "test_service",
815 Version: "0.1.0",
816 ID: info.ID,
817 Metadata: map[string]string{},
818 },
819 },
820 },
821 {

Callers

nothing calls this directly

Calls 11

HandlerFuncFuncType · 0.92
AddServiceFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerOnPortFunction · 0.70
StopMethod · 0.65
StoppedMethod · 0.65
InfoMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
RequestMethod · 0.45

Tested by

no test coverage detected