MCPcopy
hub / github.com/grafana/dskit / TestHealthCheck_List_ServiceManager

Function TestHealthCheck_List_ServiceManager

grpcutil/health_check_test.go:88–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestHealthCheck_List_ServiceManager(t *testing.T) {
89 tests := map[string]struct {
90 states []services.State
91 expected map[string]*grpc_health_v1.HealthCheckResponse
92 }{
93 "all services are new": {
94 states: []services.State{services.New, services.New},
95 expected: map[string]*grpc_health_v1.HealthCheckResponse{
96 "server": {Status: grpc_health_v1.HealthCheckResponse_NOT_SERVING},
97 },
98 },
99 }
100
101 for testName, testData := range tests {
102 t.Run(testName, func(t *testing.T) {
103 var svcs []services.Service
104 for range testData.states {
105 svcs = append(svcs, &mockService{})
106 }
107
108 ctx := context.Background()
109 req := &grpc_health_v1.HealthListRequest{}
110 sm, err := services.NewManager(svcs...)
111 require.NoError(t, err)
112
113 // Switch the state of each mocked services.
114 for i, s := range svcs {
115 s.(*mockService).switchState(testData.states[i])
116 }
117
118 h := NewHealthCheckFrom(WithManager(sm))
119 res, err := h.List(ctx, req)
120
121 require.NoError(t, err)
122 require.Equal(t, testData.expected, res.Statuses)
123 })
124 }
125}
126
127func TestHealthCheck_Check_ShutdownRequested(t *testing.T) {
128 tests := map[string]struct {

Callers

nothing calls this directly

Calls 7

NewManagerFunction · 0.92
NewHealthCheckFromFunction · 0.85
WithManagerFunction · 0.85
RunMethod · 0.80
ListMethod · 0.65
switchStateMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected