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) {
|
||||
service := in.Service
|
||||
s.mu.Lock()
|
||||
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{
|
||||
Status: status,
|
||||
}, nil
|
||||
|
@ -453,11 +453,18 @@ func testHealthCheckServingStatus(t *testing.T, e env) {
|
||||
hs := health.NewHealthServer()
|
||||
s, cc := setUp(hs, math.MaxUint32, "", e)
|
||||
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") {
|
||||
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound)
|
||||
}
|
||||
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 {
|
||||
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user