Reduce the number of IO constructors

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin
2017-12-07 14:09:08 -05:00
parent a901091f7c
commit 7d4337e738
9 changed files with 171 additions and 139 deletions

View File

@@ -3,6 +3,7 @@ package containerd
import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"runtime"
@@ -27,7 +28,7 @@ func empty() cio.Creator {
// TODO (@mlaventure) windows searches for pipes
// when none are provided
if runtime.GOOS == "windows" {
return cio.Stdio
return cio.NewCreator(cio.WithStdio)
}
return cio.NullIO
}
@@ -187,7 +188,7 @@ func TestContainerOutput(t *testing.T) {
defer container.Delete(ctx, WithSnapshotCleanup)
stdout := bytes.NewBuffer(nil)
task, err := container.NewTask(ctx, cio.NewIO(bytes.NewBuffer(nil), stdout, bytes.NewBuffer(nil)))
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
if err != nil {
t.Error(err)
return
@@ -223,6 +224,15 @@ func TestContainerOutput(t *testing.T) {
}
}
func withByteBuffers(stdout io.Writer) cio.Opt {
// TODO: could this use ioutil.Discard?
return func(streams *cio.Streams) {
streams.Stdin = new(bytes.Buffer)
streams.Stdout = stdout
streams.Stderr = new(bytes.Buffer)
}
}
func TestContainerExec(t *testing.T) {
t.Parallel()
@@ -534,7 +544,7 @@ func TestContainerCloseIO(t *testing.T) {
return
}
task, err := container.NewTask(ctx, cio.NewIO(r, stdout, ioutil.Discard))
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStreams(r, stdout, ioutil.Discard)))
if err != nil {
t.Error(err)
return
@@ -1145,7 +1155,7 @@ func TestContainerHostname(t *testing.T) {
defer container.Delete(ctx, WithSnapshotCleanup)
stdout := bytes.NewBuffer(nil)
task, err := container.NewTask(ctx, cio.NewIO(bytes.NewBuffer(nil), stdout, bytes.NewBuffer(nil)))
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
if err != nil {
t.Error(err)
return