From 709b518d033c61113ba5919ac17d97d3a89b819b Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Mon, 26 Oct 2015 16:58:09 -0700 Subject: [PATCH] Added a test for exit code 1 with docker exec --- command/agent/check_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/command/agent/check_test.go b/command/agent/check_test.go index e37609695..b737e765a 100644 --- a/command/agent/check_test.go +++ b/command/agent/check_test.go @@ -434,6 +434,25 @@ func (d *fakeDockerClientWithExecNonZeroExitCode) InspectExec(id string) (*docke }, nil } +// A fake docker client to test exit code which result into Warning +type fakeDockerClientWithExecExitCodeOne struct { +} + +func (d *fakeDockerClientWithExecExitCodeOne) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error) { + return &docker.Exec{ID: "123"}, nil +} + +func (d *fakeDockerClientWithExecExitCodeOne) StartExec(id string, opts docker.StartExecOptions) error { + return nil +} + +func (d *fakeDockerClientWithExecExitCodeOne) InspectExec(id string) (*docker.ExecInspect, error) { + return &docker.ExecInspect{ + ID: "123", + ExitCode: 1, + }, nil +} + // A fake docker client to simulate create exec failing type fakeDockerClientWithCreateExecFailure struct { } @@ -525,6 +544,10 @@ func TestDockerCheckWhenExitCodeIsNonZero(t *testing.T) { expectDockerCheckStatus(t, &fakeDockerClientWithExecNonZeroExitCode{}, "critical") } +func TestDockerCheckWhenExitCodeIsone(t *testing.T) { + expectDockerCheckStatus(t, &fakeDockerClientWithExecExitCodeOne{}, "warning") +} + func TestDockerCheckWhenExecStartFails(t *testing.T) { expectDockerCheckStatus(t, &fakeDockerClientWithStartExecFailure{}, "critical") }