Skip to content

Commit

Permalink
internal/docker: add test for explicit exit in bash scripts with -l flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Sep 14, 2018
1 parent a9e9bb1 commit 1e7ce72
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion internal/docker/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func (s *S) TestSidecarExecuteIntegration(c *check.C) {
sidecar, err := NewSidecar(dClient, "")
c.Assert(err, check.IsNil)

err = sidecar.Execute(exec.ExecuteOptions{
Dir: "/",
Cmd: "/bin/sh",
Args: []string{"-c", `echo '#!/bin/bash -el' >/tmp/myscript; echo 'echo hey; exit 0; echo done' >>/tmp/myscript; chmod +x /tmp/myscript`},
})
c.Assert(err, check.IsNil)

tt := []struct {
Name string
Cmd string
Expand All @@ -68,6 +75,7 @@ func (s *S) TestSidecarExecuteIntegration(c *check.C) {

expectedOut string
expectedErrOut string
expectedErr string
}{
{
Name: "simple",
Expand Down Expand Up @@ -131,6 +139,21 @@ func (s *S) TestSidecarExecuteIntegration(c *check.C) {
Envs: []string{"MYENV={'a': 'b', 'a2': 'b2'}"},
expectedOut: "{'a': 'b', 'a2': 'b2'}\n",
},
{
Name: "exit-with-error",
Cmd: "/bin/sh",
Dir: "/",
Args: []string{"-lc", "exit 99"},
expectedErr: `unexpected exit code 99 while running.*`,
},
{
Name: "env-and-exit",
Cmd: "/bin/sh",
Dir: "/",
Args: []string{"-lc", "/tmp/myscript xxx"},
Envs: []string{"MYENV={}", "OTHERENV=x"},
expectedOut: "hey\n",
},
}

for _, t := range tt {
Expand All @@ -145,7 +168,11 @@ func (s *S) TestSidecarExecuteIntegration(c *check.C) {
Stderr: errBuff,
})
out, errOutput := outBuff.String(), errBuff.String()
c.Check(err, check.IsNil, check.Commentf("[%v] error checking file uploaded: %v. Output: %v. Err output: %v", t.Name, err, out, errOutput))
if t.expectedErr != "" {
c.Check(err, check.ErrorMatches, t.expectedErr)
} else {
c.Check(err, check.IsNil, check.Commentf("[%v] error checking file uploaded: %v. Output: %v. Err output: %v", t.Name, err, out, errOutput))
}
c.Check(out, check.DeepEquals, t.expectedOut, check.Commentf("[%v] unexpected output. Err output: %v", t.Name, errOutput))
c.Check(errOutput, check.DeepEquals, t.expectedErrOut, check.Commentf("[%v] unexpected error output", t.Name))
}
Expand Down

0 comments on commit 1e7ce72

Please sign in to comment.