Files
docker-cli/cli/connhelper/commandconn/commandconn_unix_test.go
Sebastiaan van Stijn 2ae223038c remove pre-go1.17 build-tags
Removed pre-go1.17 build-tags with go fix;

    go mod init
    go fix -mod=readonly ./...
    rm go.mod

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-05 18:23:03 +02:00

45 lines
1.1 KiB
Go

//go:build !windows
package commandconn
import (
"context"
"io"
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
// For https://github.com/docker/cli/pull/1014#issuecomment-409308139
func TestEOFWithError(t *testing.T) {
ctx := context.TODO()
cmd := "sh"
args := []string{"-c", "echo hello; echo some error >&2; exit 42"}
c, err := New(ctx, cmd, args...)
assert.NilError(t, err)
b := make([]byte, 32)
n, err := c.Read(b)
assert.Check(t, is.Equal(len("hello\n"), n))
assert.NilError(t, err)
n, err = c.Read(b)
assert.Check(t, is.Equal(0, n))
assert.ErrorContains(t, err, "some error")
assert.ErrorContains(t, err, "42")
}
func TestEOFWithoutError(t *testing.T) {
ctx := context.TODO()
cmd := "sh"
args := []string{"-c", "echo hello; echo some debug log >&2; exit 0"}
c, err := New(ctx, cmd, args...)
assert.NilError(t, err)
b := make([]byte, 32)
n, err := c.Read(b)
assert.Check(t, is.Equal(len("hello\n"), n))
assert.NilError(t, err)
n, err = c.Read(b)
assert.Check(t, is.Equal(0, n))
assert.Check(t, is.Equal(io.EOF, err))
}