-
Notifications
You must be signed in to change notification settings - Fork 2k
run: correctly handle only STDIN attached #5662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aee9eeb
8431298
446f36c
a3d9fc4
30c4637
7dab597
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,13 @@ package container | |
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/creack/pty" | ||
"github.com/docker/cli/e2e/internal/fixtures" | ||
"github.com/docker/cli/internal/test/environment" | ||
"github.com/docker/docker/api/types/versions" | ||
|
@@ -38,6 +40,39 @@ func TestRunAttachedFromRemoteImageAndRemove(t *testing.T) { | |
golden.Assert(t, result.Stderr(), "run-attached-from-remote-and-remove.golden") | ||
} | ||
|
||
func TestRunAttach(t *testing.T) { | ||
skip.If(t, environment.RemoteDaemon()) | ||
t.Parallel() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like these changes landed in the wrong commit (probably you wanted to put them in the commit before this 🙈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahhhhhh 🤦♀️ that's what I get for trying to do 3 things at the same time. |
||
|
||
streams := []string{"stdin", "stdout", "stderr"} | ||
for _, stream := range streams { | ||
t.Run(stream, func(t *testing.T) { | ||
t.Parallel() | ||
c := exec.Command("docker", "run", "-a", stream, "--rm", "alpine", | ||
"sh", "-c", "sleep 1 && exit 7") | ||
d := bytes.Buffer{} | ||
c.Stdout = &d | ||
c.Stderr = &d | ||
_, err := pty.Start(c) | ||
assert.NilError(t, err) | ||
|
||
done := make(chan error) | ||
go func() { | ||
done <- c.Wait() | ||
}() | ||
|
||
select { | ||
case <-time.After(20 * time.Second): | ||
laurazard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Fatal("docker run took too long, likely hang", d.String()) | ||
case <-done: | ||
} | ||
|
||
assert.Equal(t, c.ProcessState.ExitCode(), 7) | ||
assert.Check(t, is.Contains(d.String(), "exit status 7")) | ||
}) | ||
} | ||
} | ||
|
||
// Regression test for https://github.com/docker/cli/issues/5053 | ||
func TestRunInvalidEntrypointWithAutoremove(t *testing.T) { | ||
environment.SkipIfDaemonNotLinux(t) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious (but perhaps for separate) if we should check if either STDOUT or STDERR is a terminal (for cases where one of them may be redirected). That's mostly with an (unrelated) discussion in the back of my head, where we didn't take that case into account.