From 8d44f2342f185e0195acbdccc30eb9ac2d741d20 Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Tue, 18 Feb 2025 23:13:53 +0800 Subject: [PATCH] fix: add media type in the generated index.json file (#894) Add a media type field in the `index.json` file generated during the OCI store initialization. Fixes: #880 Signed-off-by: Lixia (Sylvia) Lei --- content/oci/oci.go | 1 + content/oci/oci_test.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/content/oci/oci.go b/content/oci/oci.go index 748aeecc..33281453 100644 --- a/content/oci/oci.go +++ b/content/oci/oci.go @@ -379,6 +379,7 @@ func (s *Store) loadIndexFile(ctx context.Context) error { Versioned: specs.Versioned{ SchemaVersion: 2, // historical value }, + MediaType: ocispec.MediaTypeImageIndex, Manifests: []ocispec.Descriptor{}, } return s.writeIndexFile() diff --git a/content/oci/oci_test.go b/content/oci/oci_test.go index d41e3761..fd7b0cca 100644 --- a/content/oci/oci_test.go +++ b/content/oci/oci_test.go @@ -125,6 +125,9 @@ func TestStore_Success(t *testing.T) { if want := 2; index.SchemaVersion != want { t.Errorf("index.SchemaVersion = %v, want %v", index.SchemaVersion, want) } + if want := "application/vnd.oci.image.index.v1+json"; index.MediaType != want { + t.Errorf("index.MediaType = %s, want %s", index.MediaType, want) + } // test push blob err = s.Push(ctx, blobDesc, bytes.NewReader(blob))