Skip to content

Commit

Permalink
fix: fixed image size not counting config and manifest sizes (project…
Browse files Browse the repository at this point in the history
…-zot#937)

Signed-off-by: Ana-Roberta Lisca <[email protected]>
  • Loading branch information
aokirisaki authored Nov 4, 2022
1 parent 4170d2a commit eb72290
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
9 changes: 9 additions & 0 deletions pkg/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions pkg/cli/image_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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"}
Expand Down

0 comments on commit eb72290

Please sign in to comment.