Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #14 from uber/typo
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv authored Sep 7, 2017
2 parents d8c9331 + a53105c commit 85e4d9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
10 changes: 5 additions & 5 deletions tcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import (
const (
_serviceName = "tcheck"

_exitUnknown = 1
_exitUsage = 2
_exitUnknownUnhealthy = 3
_exitExplitiUnhealthy = 4
_exitUnknown = 1
_exitUsage = 2
_exitUnknownUnhealthy = 3
_exitExplicitUnhealthy = 4
)

var _osExit = os.Exit
Expand Down Expand Up @@ -109,7 +109,7 @@ func healthCheck(peer, serviceName string, timeout time.Duration) error {
return exitError{_exitUnknownUnhealthy, fmt.Sprintf("NOT OK %v\nError: %v\n", serviceName, err)}
}
if val.Ok != true {
return exitError{_exitExplitiUnhealthy, fmt.Sprintf("NOT OK %v\n", *val.Message)}
return exitError{_exitExplicitUnhealthy, fmt.Sprintf("NOT OK %v\n", val.GetMessage())}
}

return nil
Expand Down
32 changes: 28 additions & 4 deletions tcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import (
"testing"
"time"

"github.com/uber/tchannel-go"
"github.com/uber/tchannel-go/testutils"
"github.com/uber/tchannel-go/thrift"
"github.com/uber/tcheck/internal/gen-go/meta"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber/tchannel-go"
"github.com/uber/tchannel-go/testutils"
"github.com/uber/tchannel-go/thrift"
)

func healthNotOk(ctx thrift.Context) (ok bool, message string) {
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestHealthCheckBadArgs(t *testing.T) {
msg: "unhealthy health handler",
peer: unhealthyHandler.PeerInfo().HostPort,
svc: "svc",
wantExit: _exitExplitiUnhealthy,
wantExit: _exitExplicitUnhealthy,
wantErr: "test-error",
},
{
Expand Down Expand Up @@ -193,6 +194,29 @@ func TestIntegrationSuccess(t *testing.T) {
main()
}

type unhealthyHandler struct {
// Embed interface so unimplemented methods cause panic.
meta.TChanMeta
}

func (unhealthyHandler) Health(_ thrift.Context) (*meta.HealthStatus, error) {
return &meta.HealthStatus{
Ok: false,
}, nil
}

func TestIntegrationNotOKNoMessage(t *testing.T) {
server := setupServer(t, nil)
defer server.Close()

tServer := thrift.NewServer(server)
tServer.Register(meta.NewTChanMetaServer(unhealthyHandler{}))

err := healthCheck(server.PeerInfo().HostPort, server.ServiceName(), time.Second)
require.Error(t, err, "Expected health check to fail")
assert.Equal(t, _exitExplicitUnhealthy, getExitCode(err), "Unexpected exit code")
}

func TestIntegrationError(t *testing.T) {
defer func() { _osExit = os.Exit }()

Expand Down

0 comments on commit 85e4d9e

Please sign in to comment.