Skip to content

Commit

Permalink
Fixing an error when format is not specified when creating an image i…
Browse files Browse the repository at this point in the history
…ndex

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed May 6, 2024
1 parent b2ad463 commit 6e7f0f2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
3 changes: 3 additions & 0 deletions pkg/client/manifest_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
46 changes: 32 additions & 14 deletions pkg/client/manifest_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
Expand All @@ -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,
},
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/index/index_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 6e7f0f2

Please sign in to comment.