github.com/ali-iotechsys/cli@v20.10.0+incompatible/cli/connhelper/commandconn/commandconn_unix_test.go (about) 1 // +build !windows 2 3 package commandconn 4 5 import ( 6 "context" 7 "io" 8 "testing" 9 10 "gotest.tools/v3/assert" 11 is "gotest.tools/v3/assert/cmp" 12 ) 13 14 // For https://github.com/docker/cli/pull/1014#issuecomment-409308139 15 func TestEOFWithError(t *testing.T) { 16 ctx := context.TODO() 17 cmd := "sh" 18 args := []string{"-c", "echo hello; echo some error >&2; exit 42"} 19 c, err := New(ctx, cmd, args...) 20 assert.NilError(t, err) 21 b := make([]byte, 32) 22 n, err := c.Read(b) 23 assert.Check(t, is.Equal(len("hello\n"), n)) 24 assert.NilError(t, err) 25 n, err = c.Read(b) 26 assert.Check(t, is.Equal(0, n)) 27 assert.ErrorContains(t, err, "some error") 28 assert.ErrorContains(t, err, "42") 29 } 30 31 func TestEOFWithoutError(t *testing.T) { 32 ctx := context.TODO() 33 cmd := "sh" 34 args := []string{"-c", "echo hello; echo some debug log >&2; exit 0"} 35 c, err := New(ctx, cmd, args...) 36 assert.NilError(t, err) 37 b := make([]byte, 32) 38 n, err := c.Read(b) 39 assert.Check(t, is.Equal(len("hello\n"), n)) 40 assert.NilError(t, err) 41 n, err = c.Read(b) 42 assert.Check(t, is.Equal(0, n)) 43 assert.Check(t, is.Equal(io.EOF, err)) 44 }