<commit_before>// Copyright 2016 The Linux Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package schema_test

import (
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"strings"
	"testing"

	"github.com/opencontainers/image-spec/schema"
	"github.com/opencontainers/image-spec/specs-go/v1"
)

var compatMap = map[string]string{
	"application/vnd.docker.distribution.manifest.list.v2+json": v1.MediaTypeImageManifestList,
	"application/vnd.docker.distribution.manifest.v2+json":      v1.MediaTypeImageManifest,
	"application/vnd.docker.image.rootfs.diff.tar.gzip":         v1.MediaTypeImageLayer,
	"application/vnd.docker.container.image.v1+json":            v1.MediaTypeImageConfig,
}

// convertFormats converts Docker v2.2 image format JSON documents to OCI
// format by simply replacing instances of the strings found in the compatMap
// found in the input string.
func convertFormats(input string) string {
	out := input
	for k, v := range compatMap {
		out = strings.Replace(out, k, v, -1)
	}
	return out
}

func TestBackwardsCompatibilityManifestList(t *testing.T) {
	for i, tt := range []struct {
		manifest string
		digest   string
		fail     bool
	}{
		{
			digest: "sha256:e588eb8123f2031a41f2e60bc27f30a4388e181e07410aff392f7dc96b585969",
			manifest: `{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v1+json",
         "size": 2094,
         "digest": "sha256:7820f9a86d4ad15a2c4f0c0e5479298df2aa7c2f6871288e2ef8546f3e7b6783",
         "platform": {
            "architecture": "ppc64le",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v1+json",
         "size": 1922,
         "digest": "sha256:ae1b0e06e8ade3a11267564a26e750585ba2259c0ecab59ab165ad1af41d1bdd",
         "platform": {
            "architecture": "amd64",
            "os": "linux",
            "features": [
               "sse"
            ]
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v1+json",
         "size": 2084,
         "digest": "sha256:e4c0df75810b953d6717b8f8f28298d73870e8aa2a0d5e77b8391f16fdfbbbe2",
         "platform": {
            "architecture": "s390x",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v1+json",
         "size": 2084,
         "digest": "sha256:07ebe243465ef4a667b78154ae6c3ea46fdb1582936aac3ac899ea311a701b40",
         "platform": {
            "architecture": "arm",
            "os": "linux",
            "variant": "armv7"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v1+json",
         "size": 2090,
         "digest": "sha256:fb2fc0707b86dafa9959fe3d29e66af8787aee4d9a23581714be65db4265ad8a",
         "platform": {
            "architecture": "arm64",
            "os": "linux",
            "variant": "armv8"
         }
      }
   ]
}`,
			fail: false,
		},
	} {
		sum := sha256.Sum256([]byte(tt.manifest))
		got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:]))
		if tt.digest != got {<commit_msg>Modify the test's config type<commit_after>// Copyright 2016 The Linux Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package schema_test

import (
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"strings"
	"testing"

	"github.com/opencontainers/image-spec/schema"
	"github.com/opencontainers/image-spec/specs-go/v1"
)

var compatMap = map[string]string{
	"application/vnd.docker.distribution.manifest.list.v2+json": v1.MediaTypeImageManifestList,
	"application/vnd.docker.distribution.manifest.v2+json":      v1.MediaTypeImageManifest,
	"application/vnd.docker.image.rootfs.diff.tar.gzip":         v1.MediaTypeImageLayer,
	"application/vnd.docker.container.image.v1+json":            v1.MediaTypeImageConfig,
}

// convertFormats converts Docker v2.2 image format JSON documents to OCI
// format by simply replacing instances of the strings found in the compatMap
// found in the input string.
func convertFormats(input string) string {
	out := input
	for k, v := range compatMap {
		out = strings.Replace(out, k, v, -1)
	}
	return out
}

func TestBackwardsCompatibilityManifestList(t *testing.T) {
	for i, tt := range []struct {
		manifest string
		digest   string
		fail     bool
	}{
		{
			digest: "sha256:219f4b61132fe9d09b0ec5c15517be2ca712e4744b0e0cc3be71295b35b2a467",
			manifest: `{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 2094,
         "digest": "sha256:7820f9a86d4ad15a2c4f0c0e5479298df2aa7c2f6871288e2ef8546f3e7b6783",
         "platform": {
            "architecture": "ppc64le",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1922,
         "digest": "sha256:ae1b0e06e8ade3a11267564a26e750585ba2259c0ecab59ab165ad1af41d1bdd",
         "platform": {
            "architecture": "amd64",
            "os": "linux",
            "features": [
               "sse"
            ]
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 2084,
         "digest": "sha256:e4c0df75810b953d6717b8f8f28298d73870e8aa2a0d5e77b8391f16fdfbbbe2",
         "platform": {
            "architecture": "s390x",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 2084,
         "digest": "sha256:07ebe243465ef4a667b78154ae6c3ea46fdb1582936aac3ac899ea311a701b40",
         "platform": {
            "architecture": "arm",
            "os": "linux",
            "variant": "armv7"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 2090,
         "digest": "sha256:fb2fc0707b86dafa9959fe3d29e66af8787aee4d9a23581714be65db4265ad8a",
         "platform": {
            "architecture": "arm64",
            "os": "linux",
            "variant": "armv8"
         }
      }
   ]
}`,
			fail: false,
		},
	} {
		sum := sha256.Sum256([]byte(tt.manifest))
		got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:]))
		if tt.digest != got {
{'fraction_non_alphanumeric': 0.12616573407940315, 'fraction_numerical': 0.08619770849986677, 'mean_word_length': 2.755377688844422, 'pattern_counts': {'":': 80, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3393236', 'n_tokens_mistral': 2963, 'n_tokens_neox': 2521, 'n_words': 490}