diff --git a/pkg/client/manifest_create.go b/pkg/client/manifest_create.go index bfa9ee6ef0..81ffe3c03e 100644 --- a/pkg/client/manifest_create.go +++ b/pkg/client/manifest_create.go @@ -73,6 +73,9 @@ func parseOptsToIndexOptions(opts CreateManifestOptions) (idxOpts []imgutil.Inde imgutil.WithInsecure(), } } + if opts.Format == "" { + opts.Format = types.OCIImageIndex + } return []imgutil.IndexOption{ imgutil.WithMediaType(opts.Format), } diff --git a/pkg/client/manifest_create_test.go b/pkg/client/manifest_create_test.go index d61530a0d1..d1f65bff4d 100644 --- a/pkg/client/manifest_create_test.go +++ b/pkg/client/manifest_create_test.go @@ -92,19 +92,38 @@ func testCreateManifest(t *testing.T, when spec.G, it spec.S) { indexLocalPath = filepath.Join(tmpDir, imgutil.MakeFileSafeName(indexRepoName)) }) - it("creates the index adding the manifest", func() { - err = subject.CreateManifest( - context.TODO(), - CreateManifestOptions{ - IndexRepoName: indexRepoName, - RepoNames: []string{"busybox:1.36-musl"}, - Format: types.OCIImageIndex, - }, - ) - h.AssertNil(t, err) - index := h.ReadIndexManifest(t, indexLocalPath) - h.AssertEq(t, len(index.Manifests), 1) - h.AssertEq(t, index.MediaType, types.OCIImageIndex) + when("no media type is provided", func() { + it("creates the index adding the manifest", func() { + err = subject.CreateManifest( + context.TODO(), + CreateManifestOptions{ + IndexRepoName: indexRepoName, + RepoNames: []string{"busybox:1.36-musl"}, + }, + ) + h.AssertNil(t, err) + index := h.ReadIndexManifest(t, indexLocalPath) + h.AssertEq(t, len(index.Manifests), 1) + // By default uses OCI media-types + h.AssertEq(t, index.MediaType, types.OCIImageIndex) + }) + }) + + when("media type is provided", func() { + it("creates the index adding the manifest", func() { + err = subject.CreateManifest( + context.TODO(), + CreateManifestOptions{ + IndexRepoName: indexRepoName, + RepoNames: []string{"busybox:1.36-musl"}, + Format: types.DockerManifestList, + }, + ) + h.AssertNil(t, err) + index := h.ReadIndexManifest(t, indexLocalPath) + h.AssertEq(t, len(index.Manifests), 1) + h.AssertEq(t, index.MediaType, types.DockerManifestList) + }) }) }) }) @@ -131,7 +150,6 @@ func testCreateManifest(t *testing.T, when spec.G, it spec.S) { CreateManifestOptions{ IndexRepoName: indexRepoName, RepoNames: []string{"busybox:1.36-musl"}, - Format: types.OCIImageIndex, Publish: true, }, ) diff --git a/pkg/index/index_factory_test.go b/pkg/index/index_factory_test.go index d4bfe7191b..da3c791e46 100644 --- a/pkg/index/index_factory_test.go +++ b/pkg/index/index_factory_test.go @@ -109,7 +109,7 @@ func testIndexFactory(t *testing.T, when spec.G, it spec.S) { indexRepoName = h.NewRandomIndexRepoName() }) - it("errors a message", func() { + it("errors with a message", func() { _, err = indexFactory.LoadIndex(indexRepoName) h.AssertError(t, err, fmt.Sprintf("Image: '%s' not found", indexRepoName)) }) @@ -137,7 +137,7 @@ func testIndexFactory(t *testing.T, when spec.G, it spec.S) { indexRepoName = h.NewRandomIndexRepoName() }) - it("errors a message", func() { + it("errors with a message", func() { _, err = indexFactory.FetchIndex(indexRepoName, imgutil.FromBaseIndex(indexRepoName)) h.AssertNotNil(t, err) })