Skip to content

Commit

Permalink
Merge pull request hyperhq#356 from YaoZengzeng/test-exec-process
Browse files Browse the repository at this point in the history
integration test for exec --process
  • Loading branch information
laijs authored Sep 30, 2016
2 parents 0559379 + b36b712 commit 8b19c0e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions integration-test/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package main

import (
"bytes"
"encoding/json"
"io/ioutil"
"os/exec"
"path/filepath"
"time"

"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
"github.com/kr/pty"
"github.com/opencontainers/runtime-spec/specs-go"
)

func (s *RunVSuite) TestExecHelloWorld(c *check.C) {
Expand Down Expand Up @@ -85,3 +89,51 @@ func (s *RunVSuite) TestExecWithTty(c *check.C) {
c.Assert(bytes.Contains(buf, []byte("Linux")), checker.Equals, true, check.Commentf(string(buf[:n])))
<-exitChan
}

func (s *RunVSuite) TestExecWithProcessJson(c *check.C) {
process := specs.Process{
Terminal: false,
User: specs.User{},
Args: []string{
"echo", "hello",
},
Env: []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm",
},
Cwd: "/",
}

data, err := json.MarshalIndent(&process, "", "\t")
c.Assert(err, checker.IsNil)

processPath := filepath.Join(s.bundlePath, "process.json")
err = ioutil.WriteFile(processPath, data, 0666)
c.Assert(err, checker.IsNil)

ctrName := "TestExecWithProcessJson"
spec := defaultTestSpec
spec.Process.Args = []string{"sleep", "10"}
c.Assert(s.addSpec(&spec), checker.IsNil)
exitChan := make(chan struct{}, 0)

go func() {
defer close(exitChan)
_, exitCode := s.runvCommand(c, "start", "--bundle", s.bundlePath, ctrName)
c.Assert(exitCode, checker.Equals, 0)
}()

for count := 0; count < 10; count++ {
_, exitCode, err := s.runvCommandWithError("state", ctrName)
if exitCode == 0 {
c.Assert(err, checker.IsNil)
break
}
time.Sleep(1 * time.Second)
}

out, exitCode := s.runvCommand(c, "exec", "-p", processPath, ctrName)
c.Assert(out, checker.Equals, "hello\n")
c.Assert(exitCode, checker.Equals, 0)
<-exitChan
}

0 comments on commit 8b19c0e

Please sign in to comment.