helpers

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 15 Imported by: ? 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 helpers provides shared test utilities for integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FaultConfig

type FaultConfig struct {
	// LatencyPerRequest is an artificial delay applied before processing.
	LatencyPerRequest time.Duration

	// FailAfterNBytes causes the connection to be force-closed after writing
	// this many bytes of the response body.  0 = disabled.
	FailAfterNBytes int64

	// StatusCodeOverride forces every matching request to return this HTTP
	// status code.  0 = disabled.
	StatusCodeOverride int

	// FailOnNthRequest makes the first N requests (1-based) fail with 500.
	// Request N+1 and onwards succeed normally.  0 = disabled.
	FailOnNthRequest int

	// PathFaults maps a path suffix to a FaultConfig that overrides the global
	// config for requests whose URL path ends with that suffix.
	PathFaults map[string]*FaultConfig
}

FaultConfig describes fault injection parameters for the mock registry. Path-specific faults (via PathFaults) override the global config when the request path has a matching suffix.

type MockRegistry

type MockRegistry struct {
	// contains filtered or unexported fields
}

MockRegistry is an in-memory OCI Distribution API server backed by httptest.Server. It is safe for concurrent use.

func NewMockRegistry

func NewMockRegistry() *MockRegistry

NewMockRegistry creates and starts a new mock OCI registry server.

func (*MockRegistry) AddBlob

func (r *MockRegistry) AddBlob(content []byte) string

AddBlob stores content and returns its OCI digest string.

func (*MockRegistry) AddBlobWithDigest

func (r *MockRegistry) AddBlobWithDigest(digest string, content []byte) *MockRegistry

AddBlobWithDigest stores content under a caller-supplied digest string. This is useful for corruption tests where the stored digest does not match the actual content.

func (*MockRegistry) AddManifest

func (r *MockRegistry) AddManifest(ref string, manifest ocispec.Manifest) *MockRegistry

AddManifest serialises manifest and stores it under "repo:ref".

func (*MockRegistry) BlobExists

func (r *MockRegistry) BlobExists(digest string) bool

BlobExists reports whether a blob with the given digest is stored.

func (*MockRegistry) Close

func (r *MockRegistry) Close()

Close shuts down the underlying httptest.Server.

func (*MockRegistry) GetBlob

func (r *MockRegistry) GetBlob(digest string) ([]byte, bool)

GetBlob returns the content for the given digest, and whether it was found.

func (*MockRegistry) Host

func (r *MockRegistry) Host() string

Host returns "127.0.0.1:PORT" (no scheme) suitable for use as an OCI registry reference host.

func (*MockRegistry) ManifestExists

func (r *MockRegistry) ManifestExists(ref string) bool

ManifestExists reports whether a manifest stored under ref exists.

func (*MockRegistry) RequestCount

func (r *MockRegistry) RequestCount() int64

RequestCount returns the total number of requests received.

func (*MockRegistry) RequestCountByPath

func (r *MockRegistry) RequestCountByPath(pathSuffix string) int64

RequestCountByPath returns the number of requests whose URL path ends with pathSuffix. It works independently of fault configuration: every incoming request path is tracked, so callers do not need to declare a PathFault entry to observe request counts.

func (*MockRegistry) SetKeepAlivesEnabled

func (r *MockRegistry) SetKeepAlivesEnabled(v bool)

SetKeepAlivesEnabled controls HTTP keep-alives on the mock server.

Each backend operation builds its own http.Transport (pkg/backend/remote) and never closes its idle keep-alive connections. Both ends of those connections live in the test process, so goroutine-counting tests disable keep-alives to measure real leaks instead of idle connections.

func (*MockRegistry) WithFault

func (r *MockRegistry) WithFault(f *FaultConfig) *MockRegistry

WithFault sets global fault injection config and returns the registry for chaining. It also resets the failCounter so that FailOnNthRequest behaves correctly when WithFault is called multiple times on the same registry.

type TrackingReadCloser

type TrackingReadCloser struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

TrackingReadCloser wraps an io.ReadCloser and records whether Close() was called.

func NewTrackingReadCloser

func NewTrackingReadCloser(rc io.ReadCloser) *TrackingReadCloser

NewTrackingReadCloser wraps rc with close-tracking.

func (*TrackingReadCloser) AssertClosed

func (t *TrackingReadCloser) AssertClosed(tb testing.TB)

AssertClosed asserts Close() was called.

func (*TrackingReadCloser) AssertNotClosed

func (t *TrackingReadCloser) AssertNotClosed(tb testing.TB)

AssertNotClosed asserts Close() was NOT called (for reverse assertions on known bugs).

func (*TrackingReadCloser) Close

func (t *TrackingReadCloser) Close() error

Close marks the closer as closed and delegates to the underlying closer.

func (*TrackingReadCloser) WasClosed

func (t *TrackingReadCloser) WasClosed() bool

WasClosed returns true if Close() was called.

Jump to

Keyboard shortcuts

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