From 2fdcf1ae286c327e89c8853a0249ba406aea742e Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Mon, 26 Oct 2015 20:21:50 -0700 Subject: [PATCH] Added a test for selecting shell from env --- command/agent/check_test.go | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/command/agent/check_test.go b/command/agent/check_test.go index f67e8bfe22..2e9c2efa39 100644 --- a/command/agent/check_test.go +++ b/command/agent/check_test.go @@ -584,6 +584,56 @@ func TestDockerCheckWhenExecInfoFails(t *testing.T) { expectDockerCheckStatus(t, &fakeDockerClientWithExecInfoErrors{}, "critical", "Unable to inspect Exec: Unable to query exec info") } +func TestDockerCheckDefaultToSh(t *testing.T) { + mock := &MockNotify{ + state: make(map[string]string), + updates: make(map[string]int), + output: make(map[string]string), + } + check := &CheckDocker{ + Notify: mock, + CheckID: "foo", + Script: "/health.sh", + DockerContainerId: "54432bad1fc7", + Interval: 10 * time.Millisecond, + Logger: log.New(os.Stderr, "", log.LstdFlags), + dockerClient: &fakeDockerClientWithNoErrors{}, + } + check.Start() + defer check.Stop() + + time.Sleep(50 * time.Millisecond) + if check.Shell != "/bin/sh" { + t.Fatalf("Shell should be: %v , actual: %v", "/bin/sh", check.Shell) + } +} + +func TestDockerCheckUseShellFromEnv(t *testing.T) { + mock := &MockNotify{ + state: make(map[string]string), + updates: make(map[string]int), + output: make(map[string]string), + } + os.Setenv("SHELL", "/bin/bash") + check := &CheckDocker{ + Notify: mock, + CheckID: "foo", + Script: "/health.sh", + DockerContainerId: "54432bad1fc7", + Interval: 10 * time.Millisecond, + Logger: log.New(os.Stderr, "", log.LstdFlags), + dockerClient: &fakeDockerClientWithNoErrors{}, + } + check.Start() + defer check.Stop() + + time.Sleep(50 * time.Millisecond) + if check.Shell != "/bin/bash" { + t.Fatalf("Shell should be: %v , actual: %v", "/bin/bash", check.Shell) + } + os.Setenv("SHELL", "") +} + func TestDockerCheckTruncateOutput(t *testing.T) { mock := &MockNotify{ state: make(map[string]string),