Documentation
¶
Overview ¶
Package ocitest provides an in-process OCI registry for tests, so tests never depend on real network access or a real container registry.
Index ¶
- func NewBrokenLayerRegistry(t *testing.T, repoTag string) string
- func NewEmptyRegistry(t *testing.T, repoTag string) string
- func NewRegistry(t *testing.T, repoTag string, files map[string]string) string
- func NewZipRegistry(t *testing.T, repoTag string, files map[string]string) string
- type Credential
- type Server
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBrokenLayerRegistry ¶ added in v1.225.0
NewBrokenLayerRegistry starts an in-process OCI registry serving an image whose single layer declares the default tar+gzip media type but is not valid gzip data. The blob starts with the real gzip magic header (0x1f 0x8b) so go-containerregistry's compression sniffing selects the gzip decoder rather than treating the blob as an already-uncompressed tar (which would instead fail during tar parsing, not decompression); the remaining bytes are deliberately malformed so gzip.NewReader fails on the very first read, making the error deterministic and non-retryable.
func NewEmptyRegistry ¶ added in v1.225.0
NewEmptyRegistry starts an in-process OCI registry serving an image with no layers at all. It exercises the "manifest resolves but has zero layers" path (distinct from a network/auth failure), which real registries can legitimately serve for an empty or config-only image.
func NewRegistry ¶
NewRegistry starts an in-process OCI registry serving a single image built from files (archive path -> content, one uncompressed-tar layer). It returns the bare image reference "127.0.0.1:PORT/repoTag" (no "oci://" prefix, no scheme) -- callers building a component source.uri prefix it with "oci://" themselves. The go-containerregistry name.ParseReference function treats "127.0.0.1:PORT" addresses as plain HTTP automatically (see go-containerregistry's pkg/name/registry.go reLoopback), so no Insecure option is needed. The registry's httptest.Server is closed automatically via t.Cleanup.
func NewZipRegistry ¶
NewZipRegistry starts an in-process OCI registry serving a single image whose sole layer is a ZIP archive with media type "archive/zip" -- the format OpenTofu's native "install modules from OCI registries" feature uses (see https://opentofu.org, artifactType application/vnd.opentofu.modulepkg). Unlike NewRegistry's layer, this one is not gzip-wrapped: the blob is the raw zip bytes, matching what real OpenTofu module-package registries serve.
Types ¶
type Credential ¶
type Credential struct{ Username, Password string }
Credential is the Basic-auth identity an authenticated test registry accepts.
type Server ¶
type Server struct {
// Host is the "127.0.0.1:PORT" registry address.
Host string
// contains filtered or unexported fields
}
Server is an in-process registry that can be shut down independently of the test.
func NewServer ¶
func NewServer(t *testing.T, credential *Credential) *Server
NewServer starts an empty in-process OCI registry with the native OCI 1.1 referrers API enabled. When credential is non-nil, every request must carry exactly that Basic identity; any other request receives a 401 challenge, so a client that downgraded to anonymous or reused another registry's credentials fails visibly.
func NewServerWithOptions ¶
func NewServerWithOptions(t *testing.T, credential *Credential, options ...ServerOption) *Server
NewServerWithOptions is NewServer with registry behavior options.
func NewServerWithoutReferrers ¶
func NewServerWithoutReferrers(t *testing.T, credential *Credential) *Server
NewServerWithoutReferrers is NewServer for a registry without the OCI 1.1 referrers API, so attachment discovery has to use the referrers tag-schema fallback. Use it for fallback-only tests.
type ServerOption ¶
type ServerOption func(*serverConfig)
ServerOption customizes a test registry.
func WithTagsFollowManifestDelete ¶
func WithTagsFollowManifestDelete() ServerOption
WithTagsFollowManifestDelete makes deleting a manifest by digest also delete every tag that resolves to it, like a production registry, where a tag whose manifest is gone no longer resolves. The bare in-process registry keeps such tags, which would hide a delete that is not tag-safe.
func WithoutReferrersAPI ¶
func WithoutReferrersAPI() ServerOption
WithoutReferrersAPI turns off the OCI 1.1 referrers API, so clients must use the referrers tag-schema fallback.