address review comment regarding panic use
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
parent
e8d7941ca6
commit
5f588fbf9b
2 changed files with 8 additions and 3 deletions
|
@ -2,6 +2,7 @@ package ocischema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest"
|
||||||
|
@ -45,12 +46,13 @@ func NewManifestBuilder(bs distribution.BlobService, configJSON []byte, annotati
|
||||||
|
|
||||||
// SetMediaType assigns the passed mediatype or error if the mediatype is not a
|
// SetMediaType assigns the passed mediatype or error if the mediatype is not a
|
||||||
// valid media type for oci image manifests currently: "" or "application/vnd.oci.image.manifest.v1+json"
|
// valid media type for oci image manifests currently: "" or "application/vnd.oci.image.manifest.v1+json"
|
||||||
func (mb *Builder) SetMediaType(mediaType string) {
|
func (mb *Builder) SetMediaType(mediaType string) error {
|
||||||
if mediaType != "" && mediaType != v1.MediaTypeImageManifest {
|
if mediaType != "" && mediaType != v1.MediaTypeImageManifest {
|
||||||
panic("Invalid media type for OCI image manifest")
|
return errors.New("Invalid media type for OCI image manifest")
|
||||||
}
|
}
|
||||||
|
|
||||||
mb.mediaType = mediaType
|
mb.mediaType = mediaType
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build produces a final manifest from the given references.
|
// Build produces a final manifest from the given references.
|
||||||
|
|
|
@ -390,7 +390,10 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo
|
||||||
|
|
||||||
blobStore := env.repository.Blobs(ctx)
|
blobStore := env.repository.Blobs(ctx)
|
||||||
builder := ocischema.NewManifestBuilder(blobStore, []byte{}, map[string]string{})
|
builder := ocischema.NewManifestBuilder(blobStore, []byte{}, map[string]string{})
|
||||||
builder.(*ocischema.Builder).SetMediaType(imageMediaType)
|
err = builder.(*ocischema.Builder).SetMediaType(imageMediaType)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Add some layers
|
// Add some layers
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
|
|
Loading…
Reference in a new issue