diff --git a/internal/oci/oci.go b/internal/oci/oci.go index e27302e64f4d..4bb9a5d7c1e1 100644 --- a/internal/oci/oci.go +++ b/internal/oci/oci.go @@ -158,7 +158,7 @@ func findArtifactDescriptor(all []ocispec.Descriptor, opts downloadOptions) (oci } } if opts.artifactName == "" { - return ocispec.Descriptor{}, fmt.Errorf("no artifacts found") + return ocispec.Descriptor{}, fmt.Errorf("no artifact descriptors found") } return ocispec.Descriptor{}, fmt.Errorf("artifact %q not found", opts.artifactName) } diff --git a/internal/oci/oci_test.go b/internal/oci/oci_test.go index aecd65393ae5..e2fbfeed0bb9 100644 --- a/internal/oci/oci_test.go +++ b/internal/oci/oci_test.go @@ -18,6 +18,7 @@ package oci_test import ( "bytes" + "cmp" "context" "embed" "encoding/json" @@ -61,15 +62,16 @@ func parseTestsYAML[T any](t *testing.T) map[string]T { // testFile represents a single test file inside the testdata directory. type testFile struct { - Manifest string `json:"manifest"` - Expected string `json:"expected"` - Error string `json:"error"` - Authenticated bool `json:"authenticated"` - AuthUser string `json:"authUser"` - AuthPass string `json:"authPass"` - Artifacts map[string]string `json:"artifacts"` - ArtifactName string `json:"artifactName"` - PlainHTTP bool `json:"plainHTTP"` + Manifest string `json:"manifest"` + ManifestMediaType string `json:"manifestMediaType"` + Expected string `json:"expected"` + Error string `json:"error"` + Authenticated bool `json:"authenticated"` + AuthUser string `json:"authUser"` + AuthPass string `json:"authPass"` + Artifacts map[string]string `json:"artifacts"` + ArtifactName string `json:"artifactName"` + PlainHTTP bool `json:"plainHTTP"` } func TestDownload(t *testing.T) { @@ -170,7 +172,7 @@ func startOCIMockServer(t *testing.T, tname string, test testFile) string { // serve the manifest. if strings.Contains(r.URL.Path, "/manifests/") { - w.Header().Add("Content-Type", "application/vnd.oci.image.manifest.v1+json") + w.Header().Add("Content-Type", cmp.Or(test.ManifestMediaType, "application/vnd.oci.image.manifest.v1+json")) _, _ = w.Write([]byte(test.Manifest)) return } diff --git a/internal/oci/testdata/bad-manifest.yaml b/internal/oci/testdata/bad-manifest.yaml new file mode 100644 index 000000000000..a4d856e1bc08 --- /dev/null +++ b/internal/oci/testdata/bad-manifest.yaml @@ -0,0 +1,3 @@ +manifest: I am most definitely not an OCI manifest! +error: >- + failed to fetch successors: invalid character 'I' looking for beginning of value diff --git a/internal/oci/testdata/no-artifacts.yaml b/internal/oci/testdata/no-artifacts.yaml index 7f229dab8182..132ad4ef7928 100644 --- a/internal/oci/testdata/no-artifacts.yaml +++ b/internal/oci/testdata/no-artifacts.yaml @@ -15,4 +15,5 @@ manifest: | } artifacts: 44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a: "{}" -error: no artifacts found +error: >- + failed to find artifact: no artifact descriptors found diff --git a/internal/oci/testdata/not-a-manifest.yaml b/internal/oci/testdata/not-a-manifest.yaml new file mode 100644 index 000000000000..42c46fe43eed --- /dev/null +++ b/internal/oci/testdata/not-a-manifest.yaml @@ -0,0 +1,6 @@ +manifest: I am most definitely not an OCI manifest! +manifestMediaType: text/plain +# TODO: This seems like a misleading error message. +# Maybe add an extra check in the code for "this is not a manifest"? +error: >- + failed to find artifact: no artifact descriptors found