Skip to content

Commit

Permalink
remove incompatible in TestComposeExecTTY
Browse files Browse the repository at this point in the history
Signed-off-by: Kay Yan <kay.yan@daocloud.io>
  • Loading branch information
yankay committed Nov 21, 2023
1 parent 0e820e5 commit 27b72f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
21 changes: 6 additions & 15 deletions cmd/nerdctl/compose_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,8 @@ func newComposeExecCommand() *cobra.Command {
composeExecCommand.Flags().Bool("privileged", false, "Give extended privileges to the command")
composeExecCommand.Flags().StringP("user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
composeExecCommand.Flags().Int("index", 1, "index of the container if the service has multiple instances.")

composeExecCommand.PreRunE = func(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()
if noTTY, _ := flags.GetBool("no-TTY"); noTTY {
if err := flags.Set("tty", "false"); err != nil {
return err
}
}
return nil
}

composeExecCommand.Flags().MarkHidden("interactive")
composeExecCommand.Flags().MarkHidden("tty")
return composeExecCommand
}

Expand All @@ -69,7 +60,7 @@ func composeExecAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
tty, err := cmd.Flags().GetBool("tty")
noTty, err := cmd.Flags().GetBool("no-TTY")
if err != nil {
return err
}
Expand Down Expand Up @@ -106,8 +97,8 @@ func composeExecAction(cmd *cobra.Command, args []string) error {
return errors.New("currently flag -i and -d cannot be specified together (FIXME)")
}
// https://github.com/containerd/nerdctl/blob/v1.0.0/cmd/nerdctl/exec.go#L122
if tty && detach {
return errors.New("currently flag -t and -d cannot be specified together (FIXME)")
if !noTty && detach {
return errors.New("currently flag -d should be specified with --no-TTY (FIXME)")
}

client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address)
Expand All @@ -129,7 +120,7 @@ func composeExecAction(cmd *cobra.Command, args []string) error {
Index: index,

Interactive: interactive,
Tty: tty,
Tty: !noTty,
Detach: detach,
WorkDir: workdir,
Env: env,
Expand Down
10 changes: 5 additions & 5 deletions cmd/nerdctl/compose_exec_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ services:
defer base.ComposeCmd("-f", comp.YAMLFullPath(), "down", "-v").AssertOK()

// test basic functionality and `--workdir` flag
base.ComposeCmd("-f", comp.YAMLFullPath(), "exec", "-i=false", "-t=false", "svc0", "echo", "success").AssertOutExactly("success\n")
base.ComposeCmd("-f", comp.YAMLFullPath(), "exec", "-i=false", "-t=false", "--workdir", "/tmp", "svc0", "pwd").AssertOutExactly("/tmp\n")
base.ComposeCmd("-f", comp.YAMLFullPath(), "exec", "-i=false", "--no-TTY", "svc0", "echo", "success").AssertOutExactly("success\n")
base.ComposeCmd("-f", comp.YAMLFullPath(), "exec", "-i=false", "--no-TTY", "--workdir", "/tmp", "svc0", "pwd").AssertOutExactly("/tmp\n")
// cannot `exec` on non-running service
base.ComposeCmd("-f", comp.YAMLFullPath(), "exec", "svc1", "echo", "success").AssertFail()
}
Expand Down Expand Up @@ -165,7 +165,7 @@ services:
func TestComposeExecTTY(t *testing.T) {
// `-i` in `compose run & exec` is only supported in compose v2.
// Currently CI is using compose v1.
testutil.DockerIncompatible(t)
// testutil.DockerIncompatible(t)
base := testutil.NewBase(t)
if testutil.GetTarget() == testutil.Nerdctl {
testutil.RequireDaemonVersion(base, ">= 1.6.0-0")
Expand Down Expand Up @@ -197,8 +197,8 @@ services:
unbuffer := []string{"unbuffer"}
base.ComposeCmdWithHelper(unbuffer, "-f", comp.YAMLFullPath(), "exec", "svc0", "stty").AssertOutContains(sttyPartialOutput) // `-it`
base.ComposeCmdWithHelper(unbuffer, "-f", comp.YAMLFullPath(), "exec", "-i=false", "svc0", "stty").AssertOutContains(sttyPartialOutput) // `-t`
base.ComposeCmdWithHelper(unbuffer, "-f", comp.YAMLFullPath(), "exec", "-t=false", "svc0", "stty").AssertFail() // `-i`
base.ComposeCmdWithHelper(unbuffer, "-f", comp.YAMLFullPath(), "exec", "-i=false", "-t=false", "svc0", "stty").AssertFail()
base.ComposeCmdWithHelper(unbuffer, "-f", comp.YAMLFullPath(), "exec", "--no-TTY", "svc0", "stty").AssertFail() // `-i`
base.ComposeCmdWithHelper(unbuffer, "-f", comp.YAMLFullPath(), "exec", "-i=false", "--no-TTY", "svc0", "stty").AssertFail()
}

func TestComposeExecWithIndex(t *testing.T) {
Expand Down

0 comments on commit 27b72f7

Please sign in to comment.