File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,20 @@ const (
5555 StatusNotServing Status = 2
5656)
5757
58+ // String representation of the status.
59+ func (s Status ) String () string {
60+ switch s {
61+ case StatusUnknown :
62+ return "unknown"
63+ case StatusServing :
64+ return "serving"
65+ case StatusNotServing :
66+ return "not_serving"
67+ }
68+
69+ return fmt .Sprintf ("status_%d" , s )
70+ }
71+
5872// NewHandler wraps the supplied Checker to build an HTTP handler for gRPC's
5973// health-checking API. It returns the path on which to mount the handler and
6074// the HTTP handler itself.
Original file line number Diff line number Diff line change @@ -19,12 +19,39 @@ import (
1919 "errors"
2020 "net/http"
2121 "net/http/httptest"
22+ "strings"
2223 "testing"
24+ "testing/quick"
2325
2426 "connectrpc.com/connect"
2527 healthv1 "connectrpc.com/grpchealth/internal/gen/go/connectext/grpc/health/v1"
2628)
2729
30+ func TestCode (t * testing.T ) {
31+ t .Parallel ()
32+
33+ knownStatuses := map [Status ]struct {}{
34+ StatusUnknown : {},
35+ StatusServing : {},
36+ StatusNotServing : {},
37+ }
38+ check := func (s Status ) bool {
39+ got := s .String ()
40+ _ , known := knownStatuses [s ]
41+ return known != strings .HasPrefix (got , "status_" )
42+ }
43+ // always check named statuses
44+ for status := range knownStatuses {
45+ if ! check (status ) {
46+ t .Fatalf ("expected string representation of %q to be customized" , status )
47+ }
48+ }
49+ // probabilistically explore other statuses
50+ if err := quick .Check (check , nil /* config */ ); err != nil {
51+ t .Fatal (err )
52+ }
53+ }
54+
2855func TestHealth (t * testing.T ) {
2956 const (
3057 userFQN = "acme.user.v1.UserService"
You can’t perform that action at this time.
0 commit comments