testutil

package
v0.0.0-...-41c2ede Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil provides shared test infrastructure for image handler tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFileContent

func AssertFileContent(t *testing.T, path, expected string)

AssertFileContent asserts that the file at path has the expected content.

func AssertFileExists

func AssertFileExists(t *testing.T, path string)

AssertFileExists asserts that the file at path exists.

func AssertFileNotExists

func AssertFileNotExists(t *testing.T, path string)

AssertFileNotExists asserts that the file at path does not exist.

func BuildImageConfig

func BuildImageConfig(labels map[string]string) []byte

BuildImageConfig creates OCI image config JSON with the given labels.

func BuildManifest

func BuildManifest(config ocispecv1.Descriptor, layers ...ocispecv1.Descriptor) []byte

BuildManifest creates OCI manifest JSON with the given config and layers.

func BuildTarLayer

func BuildTarLayer(files map[string]string, headers ...tar.Header) ([]byte, error)

BuildTarLayer creates a tar archive containing files with the given name→content mapping and any additional headers. Files are written in iteration order; callers needing deterministic output should sort the keys beforehand.

func MustJSON

func MustJSON(v any) []byte

MustJSON marshals v to JSON and panics on error.

func SetupSingleManifest

func SetupSingleManifest(repo *FakeRepo, labels map[string]string, mediaType string, layers ...ocispecv1.Descriptor) (ocispecv1.Descriptor, []byte)

SetupSingleManifest creates a single-platform manifest in the fake repo with the given labels on its image config and optional layers. Returns the manifest descriptor and raw bytes.

Types

type FakeManifest

type FakeManifest struct {
	Bytes     []byte
	MediaType string
}

FakeManifest holds raw manifest bytes and their media type.

type FakeRepo

type FakeRepo struct {
	Manifests map[string]FakeManifest
	Blobs     map[string]func() io.ReadCloser

	// ResolveDesc and ResolveErr control the return values of Resolve.
	ResolveDesc ocispecv1.Descriptor
	ResolveErr  error

	// CloseErr controls the return value of Close.
	CloseErr error

	// Counters track how many times each method was called.
	ResolveCount       atomic.Int32
	FetchManifestCount atomic.Int32
	FetchBlobCount     atomic.Int32
	CloseCount         atomic.Int32
}

FakeRepo implements image.Repository for testing. It returns canned manifests and blobs keyed by digest, and tracks call counts for cache verification tests.

func NewFakeRepo

func NewFakeRepo() *FakeRepo

NewFakeRepo creates a FakeRepo with empty manifest and blob stores.

func (*FakeRepo) AddBlob

func (r *FakeRepo) AddBlob(data []byte, mediaType string) ocispecv1.Descriptor

AddBlob stores a blob and returns its descriptor.

func (*FakeRepo) AddErrorBlob

func (r *FakeRepo) AddErrorBlob(desc ocispecv1.Descriptor, readErr error)

AddErrorBlob registers a blob that returns an error on read.

func (*FakeRepo) AddManifest

func (r *FakeRepo) AddManifest(data []byte, mediaType string) ocispecv1.Descriptor

AddManifest stores a manifest and returns its descriptor.

func (*FakeRepo) Close

func (r *FakeRepo) Close() error

func (*FakeRepo) FetchBlob

func (r *FakeRepo) FetchBlob(_ context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)

func (*FakeRepo) FetchManifest

func (r *FakeRepo) FetchManifest(_ context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)

func (*FakeRepo) Resolve

func (r *FakeRepo) Resolve(_ context.Context) (ocispecv1.Descriptor, error)

Jump to

Keyboard shortcuts

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