client: ImageImportResult: prevent panic on nil reader

This panicked when creating a stub; we need to look for better ways to
allow stubbing these (perhaps we need to expose the rc / body)?

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-24 13:22:49 +02:00
parent 0b7b7625c6
commit 378116a84f
4 changed files with 16 additions and 10 deletions

View File

@@ -42,5 +42,5 @@ func (cli *Client) ImageImport(ctx context.Context, source ImageImportSource, re
if err != nil {
return ImageImportResult{}, err
}
return ImageImportResult{body: resp.Body}, nil
return ImageImportResult{rc: resp.Body}, nil
}

View File

@@ -20,16 +20,19 @@ type ImageImportOptions struct {
// ImageImportResult holds the response body returned by the daemon for image import.
type ImageImportResult struct {
body io.ReadCloser
rc io.ReadCloser
}
func (r ImageImportResult) Read(p []byte) (n int, err error) {
return r.body.Read(p)
if r.rc == nil {
return 0, io.EOF
}
return r.rc.Read(p)
}
func (r ImageImportResult) Close() error {
if r.body == nil {
if r.rc == nil {
return nil
}
return r.body.Close()
return r.rc.Close()
}

View File

@@ -42,5 +42,5 @@ func (cli *Client) ImageImport(ctx context.Context, source ImageImportSource, re
if err != nil {
return ImageImportResult{}, err
}
return ImageImportResult{body: resp.Body}, nil
return ImageImportResult{rc: resp.Body}, nil
}

View File

@@ -20,16 +20,19 @@ type ImageImportOptions struct {
// ImageImportResult holds the response body returned by the daemon for image import.
type ImageImportResult struct {
body io.ReadCloser
rc io.ReadCloser
}
func (r ImageImportResult) Read(p []byte) (n int, err error) {
return r.body.Read(p)
if r.rc == nil {
return 0, io.EOF
}
return r.rc.Read(p)
}
func (r ImageImportResult) Close() error {
if r.body == nil {
if r.rc == nil {
return nil
}
return r.body.Close()
return r.rc.Close()
}