github.com/cptung/libcompose@v0.4.3/integration/run_test.go (about) 1 package integration 2 3 import ( 4 "bufio" 5 "bytes" 6 "fmt" 7 "io" 8 "os" 9 "os/exec" 10 "strings" 11 "syscall" 12 13 . "gopkg.in/check.v1" 14 15 "github.com/kr/pty" 16 ) 17 18 // FIXME find out why it fails with "inappropriate ioctl for device" 19 func (s *CliSuite) TestRun(c *C) { 20 p := s.RandomProject() 21 cmd := exec.Command(s.command, "-f", "./assets/run/docker-compose.yml", "-p", p, "run", "hello", "echo", "test") 22 var b bytes.Buffer 23 wbuf := bufio.NewWriter(&b) 24 25 tty, err := pty.Start(cmd) 26 27 _, err = io.Copy(wbuf, tty) 28 if e, ok := err.(*os.PathError); ok && e.Err == syscall.EIO { 29 // We can safely ignore this error, because it's just 30 // the PTY telling us that it closed successfully. 31 // See: 32 // https://github.com/buildkite/agent/pull/34#issuecomment-46080419 33 err = nil 34 } 35 c.Assert(cmd.Wait(), IsNil) 36 output := string(b.Bytes()) 37 38 c.Assert(err, IsNil, Commentf("%s", output)) 39 40 name := fmt.Sprintf("%s_%s_run_1", p, "hello") 41 cn := s.GetContainerByName(c, name) 42 c.Assert(cn, NotNil) 43 44 lines := strings.Split(output, "\r\n") 45 lastLine := lines[len(lines)-2 : len(lines)-1][0] 46 47 c.Assert(cn.State.Running, Equals, false) 48 c.Assert(lastLine, Equals, "test") 49 }