artifacttest

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 27 Imported by: 1 module, 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 artifacttest provides test support for artifact repositories and the artifact service: a minimal in-memory Repository that implements the full artifact.Repository contract with failure injection, a fake signer and evidence format, and RunRepositoryConformance, the shared conformance suite every backend (local directory, local archive, S3, OCI layout, OCI registry) runs against its own implementation.

The in-memory repository is a harness, not a backend: it models the publication lifecycle (pending, completed, unavailable after interruption), conditional updates, digest-addressed reads that never serve replacement bytes, pagination, and ownership-checked locks, so service behavior such as reconciliation can be tested without a real store.

Index

Constants

View Source
const DefaultPageSize = 2

DefaultPageSize is the fake's list page size; it is small so tests exercise pagination.

View Source
const FakeEvidenceFormat = artifact.EvidenceSigstoreBundle

FakeEvidenceFormat is the evidence format of FakeSigner; the in-memory repository stores and verifies it. It stands in for a real format only inside tests.

Variables

This section is empty.

Functions

func DefaultCapabilities

func DefaultCapabilities() artifact.Capabilities

DefaultCapabilities is the full-featured capability set of the in-memory repository.

func RunRepositoryConformance

func RunRepositoryConformance(t *testing.T, h *Harness)

RunRepositoryConformance runs the shared repository contract suite against h. Every backend calls it from its own tests; backend-specific differences are expressed through Capabilities, never by omitting an operation that claims success. Operations a repository does not support must return a capability error, which the suite asserts.

Types

type FailPoint

type FailPoint string

FailPoint names an injectable interruption in the publication lifecycle.

const (
	// FailBeforePayload fails before anything changed.
	FailBeforePayload FailPoint = "before-payload"

	// FailDuringPayload fails while payload blobs are being read; the publication stays pending.
	FailDuringPayload FailPoint = "during-payload"

	// FailAfterMetadata fails after the immutable record was written but before the reference moved.
	FailAfterMetadata FailPoint = "after-metadata"

	// FailAfterCommit fails after the reference was published: the server-side commit succeeded
	// but the response was lost.
	FailAfterCommit FailPoint = "after-commit"
)

Injectable interruptions, in lifecycle order.

type FakeSigner

type FakeSigner struct {
	// Identity is the signer identity claim.
	Identity string

	// Issuer is the issuer claim.
	Issuer string
}

FakeSigner signs with a fixed identity and issuer. Evidence is bound to the subject digest.

func (*FakeSigner) Formats

func (f *FakeSigner) Formats() []artifact.EvidenceFormat

Formats implements artifact.Signer.

func (*FakeSigner) Sign

Sign implements artifact.Signer.

func (*FakeSigner) TrustedPolicy

func (f *FakeSigner) TrustedPolicy() artifact.VerificationPolicy

TrustedPolicy returns a policy that only FakeSigner with the same identity and issuer satisfies.

func (*FakeSigner) UntrustedPolicy

func (f *FakeSigner) UntrustedPolicy() artifact.VerificationPolicy

UntrustedPolicy returns a policy that no evidence from FakeSigner satisfies.

type FakeVerifier

type FakeVerifier struct{}

FakeVerifier is an artifact.Verifier for the evidence FakeSigner produces. Repositories that delegate cryptography to an injected verifier (the local repositories) use it in conformance tests, so those tests exercise the real storage and policy flow without Sigstore. It is a harness: it checks subject binding and the trust set, nothing cryptographic.

func (*FakeVerifier) Formats

func (*FakeVerifier) Formats() []artifact.EvidenceFormat

Formats implements artifact.Verifier.

func (*FakeVerifier) Verify

Verify implements artifact.Verifier. Every trust set must be satisfied by at least one evidence item bound to the subject. Malformed, unsupported, and unrelated evidence is reported and ignored; it can never override matching evidence.

type Harness

type Harness struct {
	// New returns a fresh, empty repository. It is called once per subtest; the harness never
	// shares state between subtests. Register cleanup with t.Cleanup.
	New func(t *testing.T) artifact.Repository

	// Packaging is the payload packaging used for publications; empty uses the first packaging
	// the repository advertises.
	Packaging artifact.Packaging

	// Signer produces evidence the repository can store. Nil is allowed only for repositories that
	// advertise no evidence formats; the suite then asserts Sign fails with a capability error.
	Signer artifact.Signer

	// TrustedPolicy is satisfied by evidence the Signer produced. Required when Signer is set.
	TrustedPolicy artifact.VerificationPolicy

	// UntrustedPolicy is a policy that evidence from the Signer must NOT satisfy. Required when
	// Signer is set.
	UntrustedPolicy artifact.VerificationPolicy
}

Harness configures RunRepositoryConformance for one backend.

type Options

type Options struct {
	// Alias names the repository in locators and errors; default "memory".
	Alias string

	// Capabilities overrides the default full-featured capabilities.
	Capabilities *artifact.Capabilities

	// PageSize is the list page size; default [DefaultPageSize].
	PageSize int

	// OnResolved runs after Resolve has pinned a version reference and released its internal
	// lock, so a test can move the reference to simulate a tag changing mid-operation.
	OnResolved func(ref artifact.Ref)
}

Options configure a Repository.

type Recorder

type Recorder struct {
	artifact.Service
	// contains filtered or unexported fields
}

Recorder wraps an artifact.Service and records every publication it sees: the request, with the operation identity the caller supplied, and the typed result. It can also fail the first publications, which lets a test drive a wrapper-level retry through a real service.

Entry points that run artifact operations (the CLI, workflow and custom-command steps, hooks) share one service seam, so a test injects a Recorder around a real composition and compares what every entry point asked for and received.

func NewRecorder

func NewRecorder(inner artifact.Service) *Recorder

NewRecorder wraps the service.

func (*Recorder) FailPublications

func (r *Recorder) FailPublications(count int, err error)

FailPublications makes the next count publications fail with err before they reach the wrapped service. A failed attempt returns a partial result that carries the supplied operation ID.

func (*Recorder) Publish

Publish implements artifact.Service.

func (*Recorder) PublishDetailed

func (r *Recorder) PublishDetailed(ctx context.Context, request artifact.PublishRequest) (*service.PublishOutcome, error)

PublishDetailed returns the sealed Record next to the operation result, like the real service, which is what a dry run and the structured result need. The wrapped service must provide it; a service that does not still works, with an empty Record.

func (*Recorder) Requests

func (r *Recorder) Requests() []artifact.PublishRequest

Requests returns the publish requests in the order they arrived.

func (*Recorder) Results

func (r *Recorder) Results() []artifact.OperationResult

Results returns the publish results in the order they were produced.

type Repository

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

Repository is an in-memory artifact.Repository. It is safe for concurrent use.

func New

func New(opts Options) *Repository

New returns an empty in-memory repository.

func (*Repository) Calls

func (r *Repository) Calls(method string) int

Calls returns how many times the named repository method was called.

func (*Repository) Capabilities

func (r *Repository) Capabilities() artifact.Capabilities

Capabilities implements artifact.Repository.

func (*Repository) Delete

Delete implements artifact.Repository. The requested scope decides what goes: a reference scope removes only the pinned reference and keeps the record and its evidence while another reference still uses them, while a manifest or object scope removes the record, its evidence, and every reference to it. A scope the repository does not advertise is rejected, never widened.

func (*Repository) HeldLocks

func (r *Repository) HeldLocks() []string

HeldLocks lists the currently claimed resources, sorted.

func (*Repository) InjectFailure

func (r *Repository) InjectFailure(point FailPoint, err error, times int)

InjectFailure arms err to be returned from Publish at point, times times (0 means once).

func (*Repository) Inspect

Inspect implements artifact.Repository. It reads only the retained record and descriptors.

func (*Repository) IsPending

func (r *Repository) IsPending(ref artifact.Ref) bool

IsPending reports whether the reference has an in-flight or interrupted publication.

func (*Repository) List

List implements artifact.Repository, paginating over completed references only.

func (*Repository) Lock

Lock implements artifact.LockProvider. Acquisition waits for a competing owner and returns the context error, leaking nothing, when canceled. Locks never expire and are never stolen.

func (*Repository) MoveRef

func (r *Repository) MoveRef(ref artifact.Ref, to digest.Digest) bool

MoveRef repoints the version reference at another stored record digest, simulating a mutable tag being moved. It reports false when the digest is unknown.

func (*Repository) OpenDocument

OpenDocument implements artifact.Repository without touching the payload.

func (*Repository) Pin

Pin implements artifact.Repository. It acquires no lock and grants no trust.

func (*Repository) Publish

Publish implements artifact.Repository with the publication lifecycle of the contracts: the pending operation is recorded before payload changes, the immutable record is written, and the completed reference is published last. Injected failures leave the state a real interruption would. A reference that is pending for a different intent stays unavailable, with the owning operation ID in the error, instead of being stolen.

func (*Repository) Read

Read implements artifact.Repository. It serves exactly the pinned digest; once the payload of a replaced or deleted record is gone it reports not found rather than the current bytes.

func (*Repository) ReadEvidence

func (r *Repository) ReadEvidence(_ context.Context, pinned *artifact.PinnedReference) ([]artifact.EvidenceBlob, error)

ReadEvidence implements artifact.EvidenceReader.

func (*Repository) RecordDigestOf

func (r *Repository) RecordDigestOf(ref artifact.Ref) (digest.Digest, bool)

RecordDigestOf returns the record digest a version reference currently points at.

func (*Repository) Resolve

Resolve implements artifact.Repository. A pending reference is unavailable to readers; a digest reference checks the Record's embedded name.

func (*Repository) SetOnResolved

func (r *Repository) SetOnResolved(hook func(ref artifact.Ref))

SetOnResolved installs (or clears) the hook that runs after a version reference was pinned.

func (*Repository) Sign

Sign implements artifact.Repository: the evidence is stored keyed by the subject digest.

func (*Repository) TotalCalls

func (r *Repository) TotalCalls() int

TotalCalls returns the total number of repository method calls (including Capabilities-free methods only), which dry-run tests assert is zero.

func (*Repository) Verify

Verify implements artifact.Repository. It authenticates stored evidence against the policy: every trust set must be satisfied by at least one evidence item bound to the subject. Unrelated or unsupported evidence is reported and ignored; it can never override matching evidence.

func (*Repository) WriteEvidence

WriteEvidence implements artifact.EvidenceWriter.

Jump to

Keyboard shortcuts

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