Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var createDescription = "Create a static container object in Pouchd. " +
type CreateCommand struct {
*container
baseCommand

openstdin bool
}

// Init initialize create command.
Expand All @@ -42,6 +44,8 @@ func (cc *CreateCommand) addFlags() {
flagSet.SetInterspersed(false)

c := addCommonFlags(flagSet)
flagSet.BoolVarP(&cc.openstdin, "interactive", "i", false, "open STDIN even if not attached")

cc.container = c
}

Expand All @@ -51,6 +55,7 @@ func (cc *CreateCommand) runCreate(args []string) error {
if err != nil {
return fmt.Errorf("failed to create container: %v", err)
}
config.ContainerConfig.OpenStdin = cc.openstdin

config.Image = args[0]
if len(args) > 1 {
Expand Down
40 changes: 23 additions & 17 deletions test/cli_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
"github.com/kr/pty"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -49,32 +48,39 @@ func (suite *PouchStartSuite) TestStartCommand(c *check.C) {
command.PouchRun("stop", "-t", "1", name).Assert(c, icmd.Success)
}

// TestStartInTTY tests "pouch start -i" work.
func (suite *PouchStartSuite) TestStartInTTY(c *check.C) {
// TestStartWithStdin tests "pouch start -i" work.
func (suite *PouchStartSuite) TestStartWithStdin(c *check.C) {
// make echo server
name := "start-tty"
res := command.PouchRun("create", "--name", name, busyboxImage, "cat")
name := c.TestName()
command.PouchRun("create", "--name", name, "-i", busyboxImage, "cat").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)

// start tty and redirect
// start start
cmd := exec.Command(environment.PouchBinary, "start", "-a", "-i", name)
fd, err := pty.Start(cmd)
c.Assert(err, check.IsNil)
defer fd.Close()

msg := "Hello, Pouch"
// prepare the io stream
stdin, err := cmd.StdinPipe()
c.Assert(err, check.IsNil)
defer stdin.Close()

// hey
_, err = fd.Write([]byte(msg + "\n"))
stdout, err := cmd.StdoutPipe()
c.Assert(err, check.IsNil)
defer stdout.Close()

// what?
echo, err := bufio.NewReader(fd).ReadString('\n')
c.Assert(cmd.Start(), check.IsNil)
defer func() {
cmd.Process.Kill()
cmd.Wait()
}()

msg := "Hello, Pouch"
_, err = stdin.Write([]byte(msg + "\n"))
c.Assert(err, check.IsNil)
c.Assert(strings.TrimSpace(echo), check.Equals, msg)

command.PouchRun("stop", "-t", "1", name)
out, err := bufio.NewReader(stdout).ReadString('\n')
c.Assert(err, check.IsNil)
c.Assert(strings.TrimSpace(out), check.Equals, msg)
c.Assert(stdin.Close(), check.IsNil)
}

// TestStartInWrongWay runs start command in wrong way.
Expand Down
23 changes: 0 additions & 23 deletions vendor/github.com/kr/pty/License

This file was deleted.

36 changes: 0 additions & 36 deletions vendor/github.com/kr/pty/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions vendor/github.com/kr/pty/doc.go

This file was deleted.

13 changes: 0 additions & 13 deletions vendor/github.com/kr/pty/ioctl.go

This file was deleted.

39 changes: 0 additions & 39 deletions vendor/github.com/kr/pty/ioctl_bsd.go

This file was deleted.

19 changes: 0 additions & 19 deletions vendor/github.com/kr/pty/mktypes.bash

This file was deleted.

61 changes: 0 additions & 61 deletions vendor/github.com/kr/pty/pty_darwin.go

This file was deleted.

76 changes: 0 additions & 76 deletions vendor/github.com/kr/pty/pty_dragonfly.go

This file was deleted.

Loading