registrytest

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package registrytest spins an in-process OCI distribution registry for diffah's integration tests. Wraps go-containerregistry's in-process registry with optional Basic-auth, bearer-token, TLS, fault-injection, and access-logging middleware. Provides only what diffah needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobRequest

type BlobRequest struct {
	Repo   string
	Digest digest.Digest
}

BlobRequest records a single GET/HEAD for /v2/<repo>/blobs/<digest>.

type ManifestRequest

type ManifestRequest struct {
	Repo      string
	Reference string
	Method    string
}

ManifestRequest records a single GET/HEAD for /v2/<repo>/manifests/<reference>. Reference may be a tag (e.g. "v1") or a digest ("sha256:..."). Tracked so integration tests can budget how many times preflight + apply collectively pull a baseline manifest.

type Option

type Option func(*config)

Option configures the registrytest Server.

func WithBasicAuth

func WithBasicAuth(user, pass string) Option

WithBasicAuth enables HTTP Basic-auth middleware.

func WithBearerToken

func WithBearerToken(token string) Option

WithBearerToken enables Bearer-token middleware.

func WithInjectFault

func WithInjectFault(match func(*http.Request) bool, status, failN int) Option

WithInjectFault makes the first failN matching requests return status. Use e.g. failN=2 to exercise a 3-retry loop that succeeds on attempt 3.

func WithTLS

func WithTLS() Option

WithTLS enables HTTPS with a generated self-signed certificate. The server exposes the CA cert PEM via CACertPEM() and writes the CA cert into ClientCertDir() as "registry.crt" so --cert-dir-style consumers find the file.

type Server

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

Server is the in-process registry returned by New.

func New

func New(t *testing.T, opts ...Option) *Server

New starts a fresh in-process registry and registers t.Cleanup to shut it down. Use Options to add middleware.

func (*Server) BlobHits

func (s *Server) BlobHits() []BlobRequest

BlobHits returns every /v2/<repo>/blobs/<digest> request observed. Tests use it to assert lazy-fetch behaviour.

func (*Server) CACertPEM

func (s *Server) CACertPEM() []byte

CACertPEM returns the PEM-encoded server certificate (which doubles as the CA in this harness's self-signed chain). Empty if WithTLS was not passed.

func (*Server) ClientCertDir

func (s *Server) ClientCertDir() string

ClientCertDir returns a directory suitable for --cert-dir, containing registry.crt. Empty if WithTLS was not passed.

func (*Server) Close

func (s *Server) Close()

Close tears down the underlying httptest.Server.

func (*Server) ManifestHits

func (s *Server) ManifestHits() []ManifestRequest

ManifestHits returns every /v2/<repo>/manifests/<reference> request observed. Used by preflight tests to assert that pre-flight does not regress baseline manifest GET counts.

func (*Server) URL

func (s *Server) URL() string

URL returns the base URL of the test registry (e.g. http://127.0.0.1:XXXX).

Jump to

Keyboard shortcuts

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