Skip to content

Commit

Permalink
Image size must be set
Browse files Browse the repository at this point in the history
Adding a test

Signed-off-by: Silvin Lubecki <[email protected]>
  • Loading branch information
silvin-lubecki committed Sep 10, 2019
1 parent 0b524ad commit 3117eda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion converter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,14 @@ func makeDescriptor(baseImage bundle.BaseImage, targetReference reference.Named,
if err != nil {
return ocischemav1.Descriptor{}, err
}
if baseImage.Size == 0 {
return ocischemav1.Descriptor{}, fmt.Errorf("image %q size is not set", relocatedImage)
}

return ocischemav1.Descriptor{
Digest: digested.Digest(),
MediaType: mediaType,
Size: int64(baseImage.Size), // TODO: mutate the bundle if the size is not set
Size: int64(baseImage.Size),
}, nil
}

Expand Down
6 changes: 6 additions & 0 deletions converter/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func TestConvertFromFixedUpBundleToOCI(t *testing.T) {
assert.ErrorContains(t, err, "invalid invocation image: "+
"image \"Some/iNvalid/Ref\" is not a valid image reference: invalid reference format: repository name must be lowercase")

// Invalid size
src = tests.MakeTestBundle()
src.InvocationImages[0].Size = 0
_, err = ConvertBundleToOCIIndex(src, named, bundleConfigDescriptor, relocationMap)
assert.ErrorContains(t, err, "size is not set")

// mediatype ociindex
src = tests.MakeTestBundle()
src.InvocationImages[0].MediaType = ocischemav1.MediaTypeImageIndex
Expand Down

0 comments on commit 3117eda

Please sign in to comment.