Skip to content

Commit

Permalink
docker: add tests for sidecar.ExecuteAsUser
Browse files Browse the repository at this point in the history
  • Loading branch information
andrestc committed Apr 11, 2018
1 parent 1e9525f commit cdb95d9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/docker/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,47 @@ func (s *S) TestSidecarExecuteIntegration(c *check.C) {
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))
}
}

func (s *S) TestSidecarExecuteAsUserIntegration(c *check.C) {
checkSkip(c)

dClient, err := NewClient("")
c.Assert(err, check.IsNil)

pContID, err := setupPrimaryContainer(c, dClient)
defer func(id string) {
if id != "" {
dClient.api.RemoveContainer(docker.RemoveContainerOptions{ID: id, Force: true})
}
}(pContID)
c.Assert(err, check.IsNil)

sidecar, err := NewSidecar(dClient, "")
c.Assert(err, check.IsNil)

tt := []struct {
user string
expectedOutput string
}{
{user: "ubuntu", expectedOutput: "ubuntu\n"},
{user: "", expectedOutput: "ubuntu\n"},
{user: "root", expectedOutput: "root\n"},
}

for _, t := range tt {
outBuff := new(bytes.Buffer)
errBuff := new(bytes.Buffer)
err := sidecar.ExecuteAsUser(t.user, exec.ExecuteOptions{
Cmd: "whoami",
Stdout: outBuff,
Stderr: errBuff,
})

out, errOutput := outBuff.String(), errBuff.String()
c.Check(err, check.IsNil, check.Commentf("[%v] error running as user: %v", t.user, err))
c.Check(out, check.DeepEquals, t.expectedOutput, check.Commentf("[%v] unexpected output. Err output: %v", t.user, errOutput))
}
}

func setupPrimaryContainer(c *check.C, dClient *Client) (string, error) {
Expand Down

0 comments on commit cdb95d9

Please sign in to comment.