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

Function TestServiceStats

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

Source from the content-addressed store, hash-verified

1081}
1082
1083func TestServiceStats(t *testing.T) {
1084 handler := func(r micro.Request) {
1085 r.Respond([]byte("ok"))
1086 }
1087 tests := []struct {
1088 name string
1089 config micro.Config
1090 expectedStats map[string]any
1091 }{
1092 {
1093 name: "stats handler",
1094 config: micro.Config{
1095 Name: "test_service",
1096 Version: "0.1.0",
1097 },
1098 },
1099 {
1100 name: "with stats handler",
1101 config: micro.Config{
1102 Name: "test_service",
1103 Version: "0.1.0",
1104 StatsHandler: func(e *micro.Endpoint) any {
1105 return map[string]any{
1106 "key": "val",
1107 }
1108 },
1109 },
1110 expectedStats: map[string]any{
1111 "key": "val",
1112 },
1113 },
1114 {
1115 name: "with default endpoint",
1116 config: micro.Config{
1117 Name: "test_service",
1118 Version: "0.1.0",
1119 Endpoint: &micro.EndpointConfig{
1120 Subject: "test.func",
1121 Handler: micro.HandlerFunc(handler),
1122 Metadata: map[string]string{"test": "value"},
1123 },
1124 },
1125 },
1126 }
1127
1128 for _, test := range tests {
1129 t.Run(test.name, func(t *testing.T) {
1130 s := RunServerOnPort(-1)
1131 defer s.Shutdown()
1132
1133 nc, err := nats.Connect(s.ClientURL())
1134 if err != nil {
1135 t.Fatalf("Expected to connect to server, got %v", err)
1136 }
1137 defer nc.Close()
1138
1139 srv, err := micro.AddService(nc, test.config)
1140 if err != nil {

Callers

nothing calls this directly

Calls 14

HandlerFuncFuncType · 0.92
AddServiceFunction · 0.92
WithEndpointSubjectFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
ErrorfMethod · 0.80
RunServerOnPortFunction · 0.70
RespondMethod · 0.65
AddEndpointMethod · 0.65
StopMethod · 0.65
PublishMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected