package testingresources
import "github.com/containerd/accelerated-container-image/cmd/convertor/testingresources"
Index ¶
- Constants
- func Assert(t *testing.T, condition bool, msg string)
- func ConsistentManifestMarshal(manifest *v1.Manifest) ([]byte, error)
- func GetCustomTestResolver(t *testing.T, ctx context.Context, testRegistry *TestRegistry) remotes.Resolver
- func GetLocalRegistryPath() string
- func GetTestFetcherFromResolver(t *testing.T, ctx context.Context, resolver remotes.Resolver, ref string) remotes.Fetcher
- func GetTestPusherFromResolver(t *testing.T, ctx context.Context, resolver remotes.Resolver, ref string) remotes.Pusher
- func GetTestResolver(t *testing.T, ctx context.Context) remotes.Resolver
- func NewLocalDB() database.ConversionDatabase
- func ParseRef(ctx context.Context, ref string) (string, string, string, error)
- func RunTestWithTempDir(t *testing.T, ctx context.Context, name string, testFn func(t *testing.T, ctx context.Context, tmpDir string))
- type DockerDescriptor
- type DockerManifest
- type MockLocalFetcher
- type MockLocalPusher
- func (p MockLocalPusher) Push(ctx context.Context, desc v1.Descriptor) (content.Writer, error)
- func (p MockLocalPusher) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error)
- type MockLocalResolver
- func NewCustomMockLocalResolver(ctx context.Context, testReg *TestRegistry) (*MockLocalResolver, error)
- func NewMockLocalResolver(ctx context.Context, localRegistryPath string) (*MockLocalResolver, error)
- func (r *MockLocalResolver) Fetcher(ctx context.Context, ref string) (remotes.Fetcher, error)
- func (r *MockLocalResolver) Pusher(ctx context.Context, ref string) (remotes.Pusher, error)
- func (r *MockLocalResolver) Resolve(ctx context.Context, ref string) (string, v1.Descriptor, error)
- type RegistryOptions
- type RepoStore
- func NewRepoStore(ctx context.Context, path string, opts *RegistryOptions) *RepoStore
- func (r *RepoStore) Exists(ctx context.Context, descriptor v1.Descriptor) (bool, error)
- func (r *RepoStore) Fetch(ctx context.Context, descriptor v1.Descriptor) (io.ReadCloser, error)
- func (r *RepoStore) LoadStore(ctx context.Context) error
- func (r *RepoStore) Push(ctx context.Context, desc v1.Descriptor, tag string, content []byte) error
- func (r *RepoStore) Resolve(ctx context.Context, tag string) (v1.Descriptor, error)
- type TestRegistry
- func GetTestRegistry(t *testing.T, ctx context.Context, opts RegistryOptions) *TestRegistry
- func NewTestRegistry(ctx context.Context, opts RegistryOptions) (*TestRegistry, error)
- func (r *TestRegistry) Exists(ctx context.Context, repository string, tag string, desc v1.Descriptor) (bool, error)
- func (r *TestRegistry) Fetch(ctx context.Context, repository string, descriptor v1.Descriptor) (io.ReadCloser, error)
- func (r *TestRegistry) Mount(ctx context.Context, srcRepository string, targetRepository string, desc v1.Descriptor) error
- func (r *TestRegistry) Push(ctx context.Context, repository string, tag string, descriptor v1.Descriptor, content []byte) error
- func (r *TestRegistry) Resolve(ctx context.Context, ref string) (v1.Descriptor, error)
Constants ¶
const ( // MINIMAL MANIFESTS (For unit testing) // DOCKER V2 (amd64) DockerV2_Manifest_Simple_Ref = "sample.localstore.io/hello-world:amd64" DockerV2_Manifest_Simple_Digest = "sha256:7e9b6e7ba2842c91cf49f3e214d04a7a496f8214356f41d81a6e6dcad11f11e3" DockerV2_Manifest_Simple_Size = 525 DockerV2_Manifest_Simple_Config_Digest = "sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d" DockerV2_Manifest_Simple_Config_Size = 1470 DockerV2_Manifest_Simple_Layer_0_Digest = "sha256:719385e32844401d57ecfd3eacab360bf551a1491c05b85806ed8f1b08d792f6" DockerV2_Manifest_Simple_Layer_0_Size = 2457 // DOCKER V2 (amd64-converted) - overlaybd DockerV2_Manifest_Simple_Converted_Ref = "sample.localstore.io/hello-world:amd64-converted" DockerV2_Manifest_Simple_Converted_Digest = "sha256:42caa56a19e082b872d43f645bb392e25c9e78bce429755bd709fac598265f88" DockerV2_Manifest_Simple_Converted_Size = 641 // DOCKER MANIFEST LIST Docker_Manifest_List_Ref = "sample.localstore.io/hello-world:docker-list" Docker_Manifest_List_Digest = "sha256:726023f73a8fc5103fa6776d48090539042cb822531c6b751b1f6dd18cb5705d" )
const ( // OTHER CONSTS (For unit testing) ExpectedOverlaybdBaseLayerDigest = "sha256:a8b5fca80efae55088290f3da8110d7742de55c2a378d5ab53226a483f390e21" )
Functions ¶
func Assert ¶
func ConsistentManifestMarshal ¶
func GetCustomTestResolver ¶
func GetCustomTestResolver(t *testing.T, ctx context.Context, testRegistry *TestRegistry) remotes.Resolver
func GetLocalRegistryPath ¶
func GetLocalRegistryPath() string
func GetTestFetcherFromResolver ¶
func GetTestFetcherFromResolver(t *testing.T, ctx context.Context, resolver remotes.Resolver, ref string) remotes.Fetcher
func GetTestPusherFromResolver ¶
func GetTestPusherFromResolver(t *testing.T, ctx context.Context, resolver remotes.Resolver, ref string) remotes.Pusher
func GetTestResolver ¶
func NewLocalDB ¶
func NewLocalDB() database.ConversionDatabase
NewLocalDB returns a new local database for testing. This is a simple unoptimized in-memory database.
func ParseRef ¶
ParseRef Parses a ref into its components: host, repository, tag/digest
func RunTestWithTempDir ¶
func RunTestWithTempDir(t *testing.T, ctx context.Context, name string, testFn func(t *testing.T, ctx context.Context, tmpDir string))
RunTestWithTempDir runs the specified test function with a temporary writable directory.
Types ¶
type DockerDescriptor ¶
type DockerDescriptor struct { // MediaType is the media type of the object this schema refers to. MediaType string `json:"mediaType,omitempty"` // Size specifies the size in bytes of the blob. Size int64 `json:"size"` // Digest is the digest of the targeted content. Digest digest.Digest `json:"digest"` // URLs specifies a list of URLs from which this object MAY be downloaded URLs []string `json:"urls,omitempty"` // Annotations contains arbitrary metadata relating to the targeted content. Annotations map[string]string `json:"annotations,omitempty"` // Data is an embedding of the targeted content. This is encoded as a base64 // string when marshalled to JSON (automatically, by encoding/json). If // present, Data can be used directly to avoid fetching the targeted content. Data []byte `json:"data,omitempty"` // Platform describes the platform which the image in the manifest runs on. // // This should only be used when referring to a manifest. Platform *v1.Platform `json:"platform,omitempty"` // ArtifactType is the IANA media type of this artifact. ArtifactType string `json:"artifactType,omitempty"` }
type DockerManifest ¶
type DockerManifest struct { specs.Versioned // MediaType specifies the type of this document data structure e.g. `application/vnd.oci.image.manifest.v1+json` MediaType string `json:"mediaType,omitempty"` // Config references a configuration object for a container, by digest. // The referenced configuration object is a JSON blob that the runtime uses to set up the container. Config DockerDescriptor `json:"config"` // Layers is an indexed list of layers referenced by the manifest. Layers []DockerDescriptor `json:"layers"` // Subject is an optional link from the image manifest to another manifest forming an association between the image manifest and the other manifest. Subject *DockerDescriptor `json:"subject,omitempty"` // Annotations contains arbitrary metadata for the image manifest. Annotations map[string]string `json:"annotations,omitempty"` }
type MockLocalFetcher ¶
type MockLocalFetcher struct {
// contains filtered or unexported fields
}
FETCHER
func (*MockLocalFetcher) Fetch ¶
func (f *MockLocalFetcher) Fetch(ctx context.Context, desc v1.Descriptor) (io.ReadCloser, error)
type MockLocalPusher ¶
type MockLocalPusher struct {
// contains filtered or unexported fields
}
PUSHER
func (MockLocalPusher) Push ¶
func (p MockLocalPusher) Push(ctx context.Context, desc v1.Descriptor) (content.Writer, error)
func (MockLocalPusher) Writer ¶
func (p MockLocalPusher) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error)
Not used by overlaybd conversion
type MockLocalResolver ¶
type MockLocalResolver struct {
// contains filtered or unexported fields
}
RESOLVER
func NewCustomMockLocalResolver ¶
func NewCustomMockLocalResolver(ctx context.Context, testReg *TestRegistry) (*MockLocalResolver, error)
func NewMockLocalResolver ¶
func NewMockLocalResolver(ctx context.Context, localRegistryPath string) (*MockLocalResolver, error)
func (*MockLocalResolver) Fetcher ¶
func (*MockLocalResolver) Pusher ¶
func (*MockLocalResolver) Resolve ¶
func (r *MockLocalResolver) Resolve(ctx context.Context, ref string) (string, v1.Descriptor, error)
type RegistryOptions ¶
type RegistryOptions struct { InmemoryRegistryOnly bool // Specifies if the registry should not load any resources from storage LocalRegistryPath string // Specifies the path to the local registry ManifestPushIgnoresLayers bool // Specifies if the registry should require layers to be pushed before manifest }
type RepoStore ¶
type RepoStore struct {
// contains filtered or unexported fields
}
REPOSITORY
func NewRepoStore ¶
func NewRepoStore(ctx context.Context, path string, opts *RegistryOptions) *RepoStore
NewRepoStore creates a new repo store. Path provides the filesystem path to the OCI layout store. The inmemory component is initialized with an empty store. Both components work together to provide a unified view of the repository.
func (*RepoStore) Exists ¶
Exists checks if a blob exists in the repository
func (*RepoStore) Fetch ¶
func (r *RepoStore) Fetch(ctx context.Context, descriptor v1.Descriptor) (io.ReadCloser, error)
Fetch fetches a blob from the repository
func (*RepoStore) LoadStore ¶
LoadStore loads the OCI layout store from the provided path
func (*RepoStore) Push ¶
Push pushes a blob to the in memory repository. If the blob already exists, it returns an error. Tag is optional and can be empty.
func (*RepoStore) Resolve ¶
Resolve resolves a tag to a descriptor
type TestRegistry ¶
type TestRegistry struct {
// contains filtered or unexported fields
}
REGISTRY TestRegistry is a mock registry that can be used for testing purposes. The implementation is a combination of in memory and local storage, where the in memory storage is used for pushes and overrides. The local storage provides a prebuilt index of repositories and manifests for pulls. Features: Pull, Push, Resolve. Limitations: Cross Repository Mounts are not currently supported, Delete is not supported.
func GetTestRegistry ¶
func GetTestRegistry(t *testing.T, ctx context.Context, opts RegistryOptions) *TestRegistry
GetTestRegistry returns a TestRegistry with the specified options. If opts.LocalRegistryPath is not specified, the default local registry path will be used.
func NewTestRegistry ¶
func NewTestRegistry(ctx context.Context, opts RegistryOptions) (*TestRegistry, error)
func (*TestRegistry) Exists ¶
func (r *TestRegistry) Exists(ctx context.Context, repository string, tag string, desc v1.Descriptor) (bool, error)
func (*TestRegistry) Fetch ¶
func (r *TestRegistry) Fetch(ctx context.Context, repository string, descriptor v1.Descriptor) (io.ReadCloser, error)
func (*TestRegistry) Mount ¶
func (r *TestRegistry) Mount(ctx context.Context, srcRepository string, targetRepository string, desc v1.Descriptor) error
Mount simulates a cross repo mount by copying blobs from srcRepository to targetRepository
func (*TestRegistry) Push ¶
func (r *TestRegistry) Push(ctx context.Context, repository string, tag string, descriptor v1.Descriptor, content []byte) error
Push Adds content to the in-memory store
func (*TestRegistry) Resolve ¶
func (r *TestRegistry) Resolve(ctx context.Context, ref string) (v1.Descriptor, error)
Source Files ¶
consts.go local_db.go local_registry.go local_remotes.go local_repo.go serialize.go test_utils.go
- Version
- v1.3.0 (latest)
- Published
- Feb 13, 2025
- Platform
- linux/amd64
- Imports
- 25 packages
- Last checked
- 12 hours ago –
Tools for package owners.