(t *testing.T)
| 1081 | } |
| 1082 | |
| 1083 | func 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: µ.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 { |
nothing calls this directly
no test coverage detected