func (suite *ORASTestSuite) Test_1_Pull() {
	var (
		err       error
		ref       string
		desc      ocispec.Descriptor
		store     *orascontent.Memory
		emptyDesc ocispec.Descriptor
	)
	desc, err = Copy(newContext(), nil, ref, nil, ref)
	suite.NotNil(err, "error pulling with empty resolver")
	suite.Equal(desc, emptyDesc, "descriptor empty pulling with empty resolver")
	store = orascontent.NewMemory()
	ref = fmt.Sprintf("%s/nonexistent:test", suite.DockerRegistryHost)
	desc, err = Copy(newContext(), newResolver(), ref, store, ref)
	suite.NotNil(err, "error pulling non-existent ref")
	suite.Equal(desc, emptyDesc, "descriptor empty with error")
	store = orascontent.NewMemory()
	ref = fmt.Sprintf("%s/chart-tgz:test", suite.DockerRegistryHost)
	_, err = Copy(newContext(), newResolver(), ref, store, ref)
	suite.Nil(err, "no error pulling chart-tgz ref")
	content, err := ioutil.ReadFile(testTarball)
	suite.Nil(err, "no error loading test chart")
	name := filepath.Base(testTarball)
	_, actualContent, ok := store.GetByName(name)
	suite.True(ok, "find in memory")
	suite.Equal(content, actualContent, ".tgz content matches on pull")
	store = orascontent.NewMemory()
	ref = fmt.Sprintf("%s/chart-dir:test", suite.DockerRegistryHost)
	desc, err = Copy(newContext(), newResolver(), ref, store, ref)
	suite.Nil(err, "no error pulling chart-dir ref")
	cwd, _ := os.Getwd()
	os.Chdir(testDir)
	for _, filename := range testDirFiles {
		content, err = ioutil.ReadFile(filename)
		suite.Nil(err, fmt.Sprintf("no error loading %s", filename))
		_, actualContent, ok := store.GetByName(filename)
		suite.True(ok, "find in memory")
		suite.Equal(content, actualContent, fmt.Sprintf("%s content matches on pull", filename))
	}
	os.Chdir(cwd)
}
Pull files and verify descriptors
package oras
import (
	"archive/tar"
	"bytes"
	"compress/gzip"
	"context"
	_ "crypto/sha256"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"
	"time"
	orascontent "oras.land/oras-go/pkg/content"
	"oras.land/oras-go/pkg/target"
	"github.com/containerd/containerd/images"
	"github.com/distribution/distribution/v3/configuration"
	"github.com/distribution/distribution/v3/registry"
	_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
	digest "github.com/opencontainers/go-digest"
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
	"github.com/phayes/freeport"
	"github.com/stretchr/testify/suite"
)
var (
	testTarball  = "../../testdata/charts/chartmuseum-1.8.2.tgz"
	testDir      = "../../testdata/charts/chartmuseum"
	testDirFiles = []string{
		"Chart.yaml",
		"values.yaml",
		"README.md",
		"templates/_helpers.tpl",
		"templates/NOTES.txt",
		"templates/service.yaml",
		".helmignore",
	}
)
type ORASTestSuite struct {
	suite.Suite
	DockerRegistryHost string
}
func newContext() context.Context {
	return context.Background()
}
func newResolver() target.Target {
	reg, _ := orascontent.NewRegistry(orascontent.RegistryOptions{})
	return reg
}
func (suite *ORASTestSuite) SetupSuite() {
	config := &configuration.Configuration{}
	port, err := freeport.GetFreePort()
	if err != nil {
		suite.Nil(err, "no error finding free port for test registry")
	}
	suite.DockerRegistryHost = fmt.Sprintf("localhost:%d", port)
	config.HTTP.Addr = fmt.Sprintf(":%d", port)
	config.HTTP.DrainTimeout = time.Duration(10) * time.Second
	config.Storage = map[string]configuration.Parameters{"inmemory": map[string]interface{}{}}
	dockerRegistry, err := registry.NewRegistry(context.Background(), config)
	suite.Nil(err, "no error finding free port for test registry")
	go dockerRegistry.ListenAndServe()
}
func (suite *ORASTestSuite) Test_0_Copy() {
	var (
		err         error
		ref         string
		desc        ocispec.Descriptor
		descriptors []ocispec.Descriptor
		store       *orascontent.File
		memStore    *orascontent.Memory
	)
	_, err = Copy(newContext(), nil, ref, nil, ref)
	suite.NotNil(err, "error pushing with empty resolver")
	_, err = Copy(newContext(), orascontent.NewMemory(), ref, newResolver(), "")
	suite.NotNil(err, "error pushing when ref missing hostname")
	ref = fmt.Sprintf("%s/empty:test", suite.DockerRegistryHost)
	memStore = orascontent.NewMemory()
	config, configDesc, err := orascontent.GenerateConfig(nil)
	suite.Nil(err, "no error generating config")
	memStore.Set(configDesc, config)
	emptyManifest, emptyManifestDesc, err := orascontent.GenerateManifest(&configDesc, nil)
	suite.Nil(err, "no error creating manifest with empty descriptors")
	err = memStore.StoreManifest(ref, emptyManifestDesc, emptyManifest)
	suite.Nil(err, "no error pushing manifest with empty descriptors")
	_, err = Copy(newContext(), memStore, ref, newResolver(), "")
	suite.Nil(err, "no error pushing with empty descriptors")
	ref = fmt.Sprintf("%s/chart-tgz:test", suite.DockerRegistryHost)
	store = orascontent.NewFile("")
	err = store.Load(configDesc, config)
	suite.Nil(err, "no error loading config for test chart")
	basename := filepath.Base(testTarball)
	desc, err = store.Add(basename, "", testTarball)
	suite.Nil(err, "no error loading test chart")
	testChartManifest, testChartManifestDesc, err := orascontent.GenerateManifest(&configDesc, nil, desc)
	suite.Nil(err, "no error creating manifest with test chart descriptor")
	err = store.StoreManifest(ref, testChartManifestDesc, testChartManifest)
	suite.Nil(err, "no error pushing manifest with test chart descriptor")
	fmt.Printf("%s\n", testChartManifest)
	_, err = Copy(newContext(), store, ref, newResolver(), "")
	suite.Nil(err, "no error pushing test chart tgz (as single layer)")
	testDirAbs, err := filepath.Abs(testDir)
	suite.Nil(err, "no error parsing test directory")
	store = orascontent.NewFile(testDirAbs)
	err = store.Load(configDesc, config)
	suite.Nil(err, "no error saving config for test dir")
	descriptors = []ocispec.Descriptor{}
	var ff = func(pathX string, infoX os.FileInfo, errX error) error {
		if !infoX.IsDir() {
			filename := filepath.Join(filepath.Dir(pathX), infoX.Name())
			name := filepath.ToSlash(filename)
			desc, err = store.Add(name, "", filename)
			if err != nil {
				return err
			}
			descriptors = append(descriptors, desc)
		}
		return nil
	}
	cwd, _ := os.Getwd()
	os.Chdir(testDir)
	filepath.Walk(".", ff)
	os.Chdir(cwd)
	ref = fmt.Sprintf("%s/chart-dir:test", suite.DockerRegistryHost)
	testChartDirManifest, testChartDirManifestDesc, err := orascontent.GenerateManifest(&configDesc, nil, descriptors...)
	suite.Nil(err, "no error creating manifest with test chart dir (each file as layer)")
	err = store.StoreManifest(ref, testChartDirManifestDesc, testChartDirManifest)
	suite.Nil(err, "no error pushing manifest with test chart dir (each file as layer)")
	_, err = Copy(newContext(), store, ref, newResolver(), "")
	suite.Nil(err, "no error pushing test chart dir (each file as layer)")
}