(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func 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 | |
| 127 | func TestHealthCheck_Check_ShutdownRequested(t *testing.T) { |
| 128 | tests := map[string]struct { |
nothing calls this directly
no test coverage detected