Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/connectors/container_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func (cli *containerClient) CreateContainer(opts ContainerOpts) (string, error)
return "", err
}
defer out.Close()
io.Copy(os.Stdout, out)
if err := copyImagePullOutput(out); err != nil {
return "", err
}

resp, err := cli.cli.ContainerCreate(
ctx,
Expand Down Expand Up @@ -148,3 +150,11 @@ func (cli *containerClient) StopContainer(containerId string) error {
func (cli *containerClient) CloseClient() error {
return cli.cli.Close()
}

func copyImagePullOutput(out io.Reader) error {
_, err := io.Copy(os.Stdout, out)
if err != nil {
return fmt.Errorf("failed to read image pull output: %w", err)
}
return nil
}
35 changes: 35 additions & 0 deletions pkg/connectors/container_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package connectors

import (
"errors"
"io"
"strings"
"testing"
)

type failingReader struct{}

func (f failingReader) Read(p []byte) (int, error) {
return 0, errors.New("read failed")
}

func TestCopyImagePullOutputReturnsReadError(t *testing.T) {
err := copyImagePullOutput(failingReader{})

if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "failed to read image pull output") {
t.Fatalf("unexpected error: %v", err)
}
}

func TestCopyImagePullOutputSucceeds(t *testing.T) {
err := copyImagePullOutput(strings.NewReader(""))

if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

var _ io.Reader = failingReader{}
Loading