add empty string check
This commit is contained in:
@ -24,10 +24,14 @@ func NewHealthServer() *HealthServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
||||||
service := in.Service
|
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
if status, ok := s.statusMap[service]; ok {
|
if in.Service == "" {
|
||||||
|
return &healthpb.HealthCheckResponse{
|
||||||
|
Status: healthpb.HealthCheckResponse_SERVING,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
if status, ok := s.statusMap[in.Service]; ok {
|
||||||
return &healthpb.HealthCheckResponse{
|
return &healthpb.HealthCheckResponse{
|
||||||
Status: status,
|
Status: status,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -453,11 +453,18 @@ func testHealthCheckServingStatus(t *testing.T, e env) {
|
|||||||
hs := health.NewHealthServer()
|
hs := health.NewHealthServer()
|
||||||
s, cc := setUp(hs, math.MaxUint32, "", e)
|
s, cc := setUp(hs, math.MaxUint32, "", e)
|
||||||
defer tearDown(s, cc)
|
defer tearDown(s, cc)
|
||||||
|
out, err := healthCheck(1*time.Second, cc, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err)
|
||||||
|
}
|
||||||
|
if out.Status != healthpb.HealthCheckResponse_SERVING {
|
||||||
|
t.Fatalf("Got the serving status %v, want SERVING", out.Status)
|
||||||
|
}
|
||||||
if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck"); err != grpc.Errorf(codes.NotFound, "unknown service") {
|
if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck"); err != grpc.Errorf(codes.NotFound, "unknown service") {
|
||||||
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound)
|
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound)
|
||||||
}
|
}
|
||||||
hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", healthpb.HealthCheckResponse_SERVING)
|
hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", healthpb.HealthCheckResponse_SERVING)
|
||||||
out, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck")
|
out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err)
|
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user