Skip to content
Merged
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
18 changes: 13 additions & 5 deletions cli/command/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ func mockContainerLogsResult(content string) client.ContainerLogsResult {
return out
}

type fakeStreamResult struct {
io.ReadCloser
client.ImagePushResponse // same interface as [client.ImagePushResponse]
}

func (e fakeStreamResult) Read(p []byte) (int, error) { return e.ReadCloser.Read(p) }
func (e fakeStreamResult) Close() error { return e.ReadCloser.Close() }

type fakeClient struct {
client.Client
inspectFunc func(string) (client.ContainerInspectResult, error)
execInspectFunc func(execID string) (client.ExecInspectResult, error)
execCreateFunc func(containerID string, options client.ExecCreateOptions) (client.ExecCreateResult, error)
createContainerFunc func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error)
containerStartFunc func(containerID string, options client.ContainerStartOptions) (client.ContainerStartResult, error)
imageCreateFunc func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error)
imagePullFunc func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error)
infoFunc func() (client.SystemInfoResult, error)
containerStatPathFunc func(containerID, path string) (client.ContainerStatPathResult, error)
containerCopyFromFunc func(containerID, srcPath string) (client.CopyFromContainerResult, error)
Expand Down Expand Up @@ -107,11 +115,11 @@ func (f *fakeClient) ContainerRemove(ctx context.Context, containerID string, op
return client.ContainerRemoveResult{}, nil
}

func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
if f.imageCreateFunc != nil {
return f.imageCreateFunc(ctx, parentReference, options)
func (f *fakeClient) ImagePull(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
if f.imagePullFunc != nil {
return f.imagePullFunc(ctx, parentReference, options)
}
return client.ImageCreateResult{}, nil
return fakeStreamResult{}, nil
}

func (f *fakeClient) Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error) {
Expand Down
6 changes: 3 additions & 3 deletions cli/command/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
// Already validated.
ociPlatforms = append(ociPlatforms, platforms.MustParse(options.platform))
}
resp, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{
resp, err := dockerCli.Client().ImagePull(ctx, img, client.ImagePullOptions{
RegistryAuth: encodedAuth,
Platforms: ociPlatforms,
})
if err != nil {
return err
}
defer func() {
_ = resp.Body.Close()
_ = resp.Close()
}()

out := dockerCli.Err()
if options.quiet {
out = streams.NewOut(io.Discard)
}
return jsonstream.Display(ctx, resp.Body, out)
return jsonstream.Display(ctx, resp, out)
}

type cidFile struct {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
return client.ContainerCreateResult{ID: containerID}, nil
}
},
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
defer func() { pullCounter++ }()
return client.ImageCreateResult{Body: io.NopCloser(strings.NewReader(""))}, nil
return fakeStreamResult{ReadCloser: io.NopCloser(strings.NewReader(""))}, nil
},
infoFunc: func() (client.SystemInfoResult, error) {
return client.SystemInfoResult{
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func TestRunPullTermination(t *testing.T) {
containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) {
return client.ContainerAttachResult{}, errors.New("shouldn't try to attach to a container")
},
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
server, respReader := net.Pipe()
t.Cleanup(func() {
_ = server.Close()
Expand All @@ -260,7 +260,7 @@ func TestRunPullTermination(t *testing.T) {
}
}()
attachCh <- struct{}{}
return client.ImageCreateResult{Body: respReader}, nil
return fakeStreamResult{ReadCloser: respReader}, nil
},
Version: client.MaxAPIVersion,
})
Expand Down
Loading