Switch exec to look at exit code not output status.

This commit is contained in:
Brendan Burns
2015-05-08 09:48:31 -07:00
parent 35c644a45f
commit c9324e6e38
8 changed files with 98 additions and 12 deletions

View File

@@ -41,16 +41,40 @@ type healthCheckTest struct {
err error
}
type fakeExitError struct {
exited bool
statusCode int
}
func (f *fakeExitError) String() string {
return f.Error()
}
func (f *fakeExitError) Error() string {
return "fake exit"
}
func (f *fakeExitError) Exited() bool {
return f.exited
}
func (f *fakeExitError) ExitStatus() int {
return f.statusCode
}
func TestExec(t *testing.T) {
prober := New()
fake := FakeCmd{}
tests := []healthCheckTest{
// Ok
{probe.Success, false, []byte("OK"), nil},
// Ok
{probe.Success, false, []byte("OK"), &fakeExitError{true, 0}},
// Run returns error
{probe.Unknown, true, []byte("OK, NOT"), fmt.Errorf("test error")},
// Unhealthy
{probe.Failure, false, []byte("Fail"), nil},
{probe.Failure, false, []byte("Fail"), &fakeExitError{true, 1}},
}
for _, test := range tests {
fake.out = test.output