|
@@ -15,12 +15,17 @@ import (
|
|
|
"strings"
|
|
|
"testing"
|
|
|
|
|
|
+ "github.com/containerd/containerd/images"
|
|
|
+ "github.com/containerd/containerd/remotes/docker"
|
|
|
"github.com/docker/docker/api/types"
|
|
|
+ "github.com/docker/docker/pkg/jsonmessage"
|
|
|
"github.com/docker/docker/testutil/daemon"
|
|
|
"github.com/docker/docker/testutil/fixtures/plugin"
|
|
|
"github.com/docker/docker/testutil/registry"
|
|
|
"github.com/docker/docker/testutil/request"
|
|
|
+ v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
|
|
"gotest.tools/v3/assert"
|
|
|
+ "gotest.tools/v3/assert/cmp"
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
"gotest.tools/v3/skip"
|
|
|
)
|
|
@@ -223,3 +228,61 @@ func TestPluginsWithRuntimes(t *testing.T) {
|
|
|
assert.NilError(t, err)
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+func TestPluginBackCompatMediaTypes(t *testing.T) {
|
|
|
+ skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
|
|
+ skip.If(t, testEnv.OSType == "windows")
|
|
|
+ skip.If(t, testEnv.IsRootless, "Rootless has a different view of localhost (needed for test registry access)")
|
|
|
+
|
|
|
+ defer setupTest(t)()
|
|
|
+
|
|
|
+ reg := registry.NewV2(t)
|
|
|
+ defer reg.Close()
|
|
|
+ reg.WaitReady(t)
|
|
|
+
|
|
|
+ repo := path.Join(registry.DefaultURL, strings.ToLower(t.Name())+":latest")
|
|
|
+
|
|
|
+ client := testEnv.APIClient()
|
|
|
+
|
|
|
+ ctx := context.Background()
|
|
|
+ assert.NilError(t, plugin.Create(ctx, client, repo))
|
|
|
+
|
|
|
+ rdr, err := client.PluginPush(ctx, repo, "")
|
|
|
+ assert.NilError(t, err)
|
|
|
+ defer rdr.Close()
|
|
|
+
|
|
|
+ buf := &strings.Builder{}
|
|
|
+ assert.NilError(t, jsonmessage.DisplayJSONMessagesStream(rdr, buf, 0, false, nil), buf)
|
|
|
+
|
|
|
+ // Use custom header here because older versions of the registry do not
|
|
|
+ // parse the accept header correctly and does not like the accept header
|
|
|
+ // that the default resolver code uses. "Older registries" here would be
|
|
|
+ // like the one currently included in the test suite.
|
|
|
+ headers := http.Header{}
|
|
|
+ headers.Add("Accept", images.MediaTypeDockerSchema2Manifest)
|
|
|
+
|
|
|
+ resolver := docker.NewResolver(docker.ResolverOptions{
|
|
|
+ Headers: headers,
|
|
|
+ })
|
|
|
+ assert.NilError(t, err)
|
|
|
+
|
|
|
+ n, desc, err := resolver.Resolve(ctx, repo)
|
|
|
+ assert.NilError(t, err, repo)
|
|
|
+
|
|
|
+ fetcher, err := resolver.Fetcher(ctx, n)
|
|
|
+ assert.NilError(t, err)
|
|
|
+
|
|
|
+ rdr, err = fetcher.Fetch(ctx, desc)
|
|
|
+ assert.NilError(t, err)
|
|
|
+ defer rdr.Close()
|
|
|
+
|
|
|
+ type manifest struct {
|
|
|
+ MediaType string
|
|
|
+ v1.Manifest
|
|
|
+ }
|
|
|
+ var m manifest
|
|
|
+ assert.NilError(t, json.NewDecoder(rdr).Decode(&m))
|
|
|
+ assert.Check(t, cmp.Equal(m.MediaType, images.MediaTypeDockerSchema2Manifest))
|
|
|
+ assert.Check(t, cmp.Len(m.Layers, 1))
|
|
|
+ assert.Check(t, cmp.Equal(m.Layers[0].MediaType, images.MediaTypeDockerSchema2LayerGzip))
|
|
|
+}
|