From eb722905cb324e8c4f806a8d8e0ce2e935a3fce8 Mon Sep 17 00:00:00 2001 From: Lisca Ana-Roberta <55219463+aokirisaki@users.noreply.github.com> Date: Fri, 4 Nov 2022 19:27:34 +0200 Subject: [PATCH] fix: fixed image size not counting config and manifest sizes (#937) Signed-off-by: Ana-Roberta Lisca --- pkg/cli/client.go | 9 +++++++++ pkg/cli/image_cmd_test.go | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pkg/cli/client.go b/pkg/cli/client.go index 7817fa52..4d0eb854 100644 --- a/pkg/cli/client.go +++ b/pkg/cli/client.go @@ -290,6 +290,15 @@ func (p *requestsPool) doJob(ctx context.Context, job *manifestJob) { ) } + size += uint64(job.manifestResp.Config.Size) + + manifestSize, err := strconv.Atoi(header.Get("Content-Length")) + if err != nil { + p.outputCh <- stringResult{"", err} + } + + size += uint64(manifestSize) + image := &imageStruct{} image.verbose = *job.config.verbose image.RepoName = job.imageName diff --git a/pkg/cli/image_cmd_test.go b/pkg/cli/image_cmd_test.go index d20ca648..9777734a 100644 --- a/pkg/cli/image_cmd_test.go +++ b/pkg/cli/image_cmd_test.go @@ -1161,8 +1161,8 @@ func TestServerResponse(t *testing.T) { str := space.ReplaceAllString(buff.String(), " ") actual := strings.TrimSpace(str) So(actual, ShouldContainSubstring, "IMAGE NAME TAG DIGEST SIGNED SIZE") - So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 false 15B") - So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 false 15B") + So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 false 492B") + So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 false 492B") }) Convey("Test all images verbose", func() { @@ -1181,13 +1181,13 @@ func TestServerResponse(t *testing.T) { actual := strings.TrimSpace(str) // Actual cli output should be something similar to (order of images may differ): // IMAGE NAME TAG DIGEST CONFIG LAYERS SIZE - // repo7 test:2.0 a0ca253b b8781e88 15B + // repo7 test:2.0 a0ca253b b8781e88 492B // b8781e88 15B - // repo7 test:1.0 a0ca253b b8781e88 15B + // repo7 test:1.0 a0ca253b b8781e88 492B // b8781e88 15B So(actual, ShouldContainSubstring, "IMAGE NAME TAG DIGEST CONFIG SIGNED LAYERS SIZE") - So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 3a1d2d0c false 15B b8781e88 15B") - So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 3a1d2d0c false 15B b8781e88 15B") + So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 3a1d2d0c false 492B b8781e88 15B") + So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 3a1d2d0c false 492B b8781e88 15B") }) Convey("Test image by name", func() { @@ -1205,8 +1205,8 @@ func TestServerResponse(t *testing.T) { str := space.ReplaceAllString(buff.String(), " ") actual := strings.TrimSpace(str) So(actual, ShouldContainSubstring, "IMAGE NAME TAG DIGEST SIGNED SIZE") - So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 false 15B") - So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 false 15B") + So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 false 492B") + So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 false 492B") }) Convey("Test image by digest", func() { @@ -1225,11 +1225,11 @@ func TestServerResponse(t *testing.T) { actual := strings.TrimSpace(str) // Actual cli output should be something similar to (order of images may differ): // IMAGE NAME TAG DIGEST SIZE - // repo7 test:2.0 a0ca253b 15B - // repo7 test:1.0 a0ca253b 15B + // repo7 test:2.0 a0ca253b 492B + // repo7 test:1.0 a0ca253b 492B So(actual, ShouldContainSubstring, "IMAGE NAME TAG DIGEST SIGNED SIZE") - So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 false 15B") - So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 false 15B") + So(actual, ShouldContainSubstring, "repo7 test:2.0 883fc0c5 false 492B") + So(actual, ShouldContainSubstring, "repo7 test:1.0 883fc0c5 false 492B") Convey("nonexistent digest", func() { args := []string{"imagetest", "--digest", "d1g35t"}