Skip to content

Commit

Permalink
fail computing manifest if no refs are provided (#887)
Browse files Browse the repository at this point in the history
* fail computing digest if no refs are provided

* fix error string
  • Loading branch information
jchorl committed Dec 30, 2020
1 parent 6544cb0 commit ec3c7a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/v1/tarball/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ func writeImagesToTar(refToImage map[name.Reference]v1.Image, m []byte, size int
func calculateManifest(refToImage map[name.Reference]v1.Image) (m Manifest, err error) {
imageToTags := dedupRefToImage(refToImage)

if len(imageToTags) == 0 {
return nil, errors.New("set of images is empty")
}

for img, tags := range imageToTags {
cfgName, err := img.ConfigName()
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/v1/tarball/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,18 @@ func TestComputeManifest(t *testing.T) {
}
}

func TestComputeManifest_FailsOnNoRefs(t *testing.T) {
_, err := tarball.ComputeManifest(nil)
if err == nil || !strings.Contains(err.Error(), "set of images is empty") {
t.Error("expected calculateManifest to fail with nil input")
}

_, err = tarball.ComputeManifest(map[name.Reference]v1.Image{})
if err == nil || !strings.Contains(err.Error(), "set of images is empty") {
t.Error("expected calculateManifest to fail with empty input")
}
}

func getLayersHashes(img v1.Image) ([]string, error) {
hashes := []string{}
layers, err := img.Layers()
Expand Down

0 comments on commit ec3c7a5

Please sign in to comment.