client/image_(inspect,history,load,save): Wrap return values

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Paweł Gronowski
2025-10-20 23:37:29 +02:00
committed by Sebastiaan van Stijn
parent 7066eb3736
commit 2d69edd28a
29 changed files with 231 additions and 126 deletions

View File

@@ -25,13 +25,13 @@ func TestAPIImagesHistory(t *testing.T) {
imgID := build.Do(ctx, t, client, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)))
historydata, err := client.ImageHistory(ctx, imgID)
res, err := client.ImageHistory(ctx, imgID)
assert.NilError(t, err)
assert.Assert(t, len(historydata) != 0)
assert.Assert(t, len(res.Items) != 0)
var found bool
for _, imageLayer := range historydata {
for _, imageLayer := range res.Items {
if imageLayer.ID == imgID {
found = true
break
@@ -107,20 +107,20 @@ func TestAPIImageHistoryCrossPlatform(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := testutil.StartSpan(ctx, t)
hist, err := apiClient.ImageHistory(ctx, tc.imageRef, tc.options...)
res, err := apiClient.ImageHistory(ctx, tc.imageRef, tc.options...)
assert.NilError(t, err)
found := false
for _, layer := range hist {
for _, layer := range res.Items {
if layer.ID == imgID {
found = true
break
}
}
assert.Assert(t, found, "History should contain the built image ID")
assert.Assert(t, is.Len(hist, 3))
assert.Assert(t, is.Len(res.Items, 3))
for i, layer := range hist {
for i, layer := range res.Items {
assert.Assert(t, layer.Size >= 0, "Layer %d should not have negative size", i)
}
})

View File

@@ -145,29 +145,29 @@ func TestPruneDontDeleteUsedImage(t *testing.T) {
} {
for _, tc := range []struct {
name string
imageID func(t *testing.T, inspect image.InspectResponse) string
imageID func(t *testing.T, inspect client.ImageInspectResult) string
}{
{
name: "full id",
imageID: func(t *testing.T, inspect image.InspectResponse) string {
imageID: func(t *testing.T, inspect client.ImageInspectResult) string {
return inspect.ID
},
},
{
name: "full id without sha256 prefix",
imageID: func(t *testing.T, inspect image.InspectResponse) string {
imageID: func(t *testing.T, inspect client.ImageInspectResult) string {
return strings.TrimPrefix(inspect.ID, "sha256:")
},
},
{
name: "truncated id (without sha256 prefix)",
imageID: func(t *testing.T, inspect image.InspectResponse) string {
imageID: func(t *testing.T, inspect client.ImageInspectResult) string {
return strings.TrimPrefix(inspect.ID, "sha256:")[:8]
},
},
{
name: "repo and digest without tag",
imageID: func(t *testing.T, inspect image.InspectResponse) string {
imageID: func(t *testing.T, inspect client.ImageInspectResult) string {
skip.If(t, !testEnv.UsingSnapshotter())
return "busybox@" + inspect.ID
@@ -175,7 +175,7 @@ func TestPruneDontDeleteUsedImage(t *testing.T) {
},
{
name: "tagged and digested",
imageID: func(t *testing.T, inspect image.InspectResponse) string {
imageID: func(t *testing.T, inspect client.ImageInspectResult) string {
skip.If(t, !testEnv.UsingSnapshotter())
return "busybox:latest@" + inspect.ID
@@ -183,7 +183,7 @@ func TestPruneDontDeleteUsedImage(t *testing.T) {
},
{
name: "repo digest",
imageID: func(t *testing.T, inspect image.InspectResponse) string {
imageID: func(t *testing.T, inspect client.ImageInspectResult) string {
// graphdriver won't have a repo digest
skip.If(t, len(inspect.RepoDigests) == 0, "no repo digest")

View File

@@ -94,7 +94,7 @@ func TestRemoveByDigest(t *testing.T) {
inspect, err = apiClient.ImageInspect(ctx, "test-remove-by-digest")
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
assert.Check(t, is.DeepEqual(inspect, image.InspectResponse{}))
assert.Check(t, is.DeepEqual(inspect, client.ImageInspectResult{}))
}
func TestRemoveWithPlatform(t *testing.T) {

View File

@@ -328,8 +328,8 @@ func TestSaveAndLoadPlatform(t *testing.T) {
// load the full exported image (all platforms in it)
resp, err := apiClient.ImageLoad(ctx, rdr)
assert.NilError(t, err)
_, err = io.ReadAll(resp.Body)
resp.Body.Close()
_, err = io.ReadAll(resp)
resp.Close()
assert.NilError(t, err)
rdr.Close()
@@ -366,8 +366,8 @@ func TestSaveAndLoadPlatform(t *testing.T) {
// load the exported image on the specified platforms only
resp, err = apiClient.ImageLoad(ctx, rdr, client.ImageLoadWithPlatforms(tc.loadPlatforms...))
assert.NilError(t, err)
_, err = io.ReadAll(resp.Body)
resp.Body.Close()
_, err = io.ReadAll(resp)
resp.Close()
assert.NilError(t, err)
rdr.Close()