ocitest

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ocitest provides some helper types for writing oci-related tests. It's designed to be used alongside stretchr/testify.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBlobContent

func AssertBlobContent(t *testing.T, r oci.BlobReader, wantData []byte, wantMediaType string)

AssertBlobContent checks that r matches the expected data and has the expected content type. If wantMediaType is empty, "application/octet-stream" will be expected.

func DigestRef added in v0.0.13

func DigestRef(id string) oci.Digest

DigestRef returns a deterministic digest used as a symbolic content reference in RepoContent manifests before PushContent resolves descriptors.

func PushContent

func PushContent(r oci.Interface, rc RegistryContent) (map[string]PushedRepoContent, error)

PushContent pushes all the content in rc to r.

It returns a map mapping repository name to the descriptors describing the content that has actually been pushed.

Types

type PushedRepoContent

type PushedRepoContent struct {
	// Manifests holds an entry for each manifest identifier
	// with the descriptor for that manifest.
	Manifests map[string]oci.Descriptor

	// ManifestData holds the actually pushed data for each manifest.
	ManifestData map[string][]byte

	// Blobs holds an entry for each blob identifier
	// with the descriptor for that manifest.
	Blobs map[string]oci.Descriptor
}

PushedRepoContent mirrors RepoContent but, instead of describing content that is to be pushed, describes the content that has been pushed.

func PushRepoContent

func PushRepoContent(r oci.Interface, repo string, repoc RepoContent) (PushedRepoContent, error)

PushRepoContent pushes the content for a single repository.

type Registry

type Registry struct {
	T *testing.T
	R oci.Interface
}

Registry wraps an oci.Interface with convenience methods for pushing and verifying content in tests.

func NewRegistry

func NewRegistry(t *testing.T, r oci.Interface) Registry

NewRegistry returns a Registry instance that wraps r, providing convenience methods for pushing and checking content inside the given test instance.

When a Must* method fails, it will fail using t.

func (Registry) MustPushBlob

func (r Registry) MustPushBlob(repo string, data []byte) oci.Descriptor

MustPushBlob pushes a blob to the given repository and fails the test if it encounters an error.

func (Registry) MustPushContent

func (r Registry) MustPushContent(rc RegistryContent) map[string]PushedRepoContent

MustPushContent pushes all the content in rc to r.

It returns a map mapping repository name to the descriptors describing the content that has actually been pushed.

func (Registry) MustPushManifest

func (r Registry) MustPushManifest(repo string, jsonObject any, tag string) ([]byte, oci.Descriptor)

MustPushManifest marshals jsonObject as a manifest, pushes it to the given repository with the given tag, and fails the test if it encounters an error.

type RegistryContent

type RegistryContent map[string]RepoContent

RegistryContent specifies the contents of a registry: a map from repository name to the contents of that repository.

type Repo

type Repo struct {
	T    *testing.T
	Name string
	R    oci.Interface
}

Repo holds the information needed to interact with a specific repository within a registry during tests.

type RepoContent

type RepoContent struct {
	// Manifests maps from manifest identifier to the contents of the manifest.
	// TODO support manifest indexes too.
	Manifests map[string]oci.IndexOrManifest

	// Blobs maps from blob identifer to the contents of the blob.
	Blobs map[string]string

	// Tags maps from tag name to manifest identifier.
	Tags map[string]string
}

RepoContent specifies the content of a repository. manifests and blobs are keyed by symbolic identifiers, not used inside the registry itself, but instead placeholders for the digest of the associated content.

Digest strings inside manifests that are not valid digests will be replaced by the calculated digest of the manifest or blob with that identifier; the size and media type fields will also be filled in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL