Documentation
¶
Overview ¶
Package testutil provides shared test infrastructure for image handler tests.
Index ¶
- func AssertFileContent(t *testing.T, path, expected string)
- func AssertFileExists(t *testing.T, path string)
- func AssertFileNotExists(t *testing.T, path string)
- func BuildImageConfig(labels map[string]string) []byte
- func BuildManifest(config ocispecv1.Descriptor, layers ...ocispecv1.Descriptor) []byte
- func BuildTarLayer(files map[string]string, headers ...tar.Header) ([]byte, error)
- func MustJSON(v any) []byte
- func SetupSingleManifest(repo *FakeRepo, labels map[string]string, mediaType string, ...) (ocispecv1.Descriptor, []byte)
- type FakeManifest
- type FakeRepo
- func (r *FakeRepo) AddBlob(data []byte, mediaType string) ocispecv1.Descriptor
- func (r *FakeRepo) AddErrorBlob(desc ocispecv1.Descriptor, readErr error)
- func (r *FakeRepo) AddManifest(data []byte, mediaType string) ocispecv1.Descriptor
- func (r *FakeRepo) Close() error
- func (r *FakeRepo) FetchBlob(_ context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)
- func (r *FakeRepo) FetchManifest(_ context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)
- func (r *FakeRepo) Resolve(_ context.Context) (ocispecv1.Descriptor, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFileContent ¶
AssertFileContent asserts that the file at path has the expected content.
func AssertFileExists ¶
AssertFileExists asserts that the file at path exists.
func AssertFileNotExists ¶
AssertFileNotExists asserts that the file at path does not exist.
func BuildImageConfig ¶
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 ¶
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 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 ¶
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) FetchBlob ¶
func (r *FakeRepo) FetchBlob(_ context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)