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
- func DefaultCapabilities() artifact.Capabilities
- func RunRepositoryConformance(t *testing.T, h *Harness)
- type FailPoint
- type FakeSigner
- func (f *FakeSigner) Formats() []artifact.EvidenceFormat
- func (f *FakeSigner) Sign(_ context.Context, subject artifact.SignatureSubject) (*artifact.EvidencePayload, error)
- func (f *FakeSigner) TrustedPolicy() artifact.VerificationPolicy
- func (f *FakeSigner) UntrustedPolicy() artifact.VerificationPolicy
- type FakeVerifier
- type Harness
- type Options
- type Recorder
- func (r *Recorder) FailPublications(count int, err error)
- func (r *Recorder) Publish(ctx context.Context, request artifact.PublishRequest) (*artifact.OperationResult, error)
- func (r *Recorder) PublishDetailed(ctx context.Context, request artifact.PublishRequest) (*service.PublishOutcome, error)
- func (r *Recorder) Requests() []artifact.PublishRequest
- func (r *Recorder) Results() []artifact.OperationResult
- type Repository
- func (r *Repository) Calls(method string) int
- func (r *Repository) Capabilities() artifact.Capabilities
- func (r *Repository) Delete(_ context.Context, pinned artifact.PinnedReference, ...) (*artifact.DeleteResult, error)
- func (r *Repository) HeldLocks() []string
- func (r *Repository) InjectFailure(point FailPoint, err error, times int)
- func (r *Repository) Inspect(_ context.Context, pinned artifact.PinnedReference) (*artifact.Inspection, error)
- func (r *Repository) IsPending(ref artifact.Ref) bool
- func (r *Repository) List(_ context.Context, query artifact.ListQuery) (*artifact.ListPage, error)
- func (r *Repository) Lock(ctx context.Context, request artifact.LockRequest) (artifact.LockHandle, error)
- func (r *Repository) MoveRef(ref artifact.Ref, to digest.Digest) bool
- func (r *Repository) OpenDocument(_ context.Context, pinned artifact.PinnedReference, role artifact.DocumentRole) (*artifact.DocumentStream, error)
- func (r *Repository) Pin(ctx context.Context, ref artifact.Ref) (artifact.PinnedReference, error)
- func (r *Repository) Publish(ctx context.Context, prepared *artifact.PreparedArtifact, ...) (*artifact.PublishResult, error)
- func (r *Repository) Read(_ context.Context, pinned artifact.PinnedReference) (*artifact.Content, error)
- func (r *Repository) ReadEvidence(_ context.Context, pinned *artifact.PinnedReference) ([]artifact.EvidenceBlob, error)
- func (r *Repository) RecordDigestOf(ref artifact.Ref) (digest.Digest, bool)
- func (r *Repository) Resolve(_ context.Context, ref artifact.Ref) (artifact.PinnedReference, error)
- func (r *Repository) SetOnResolved(hook func(ref artifact.Ref))
- func (r *Repository) Sign(ctx context.Context, subject artifact.SignatureSubject, signer artifact.Signer, ...) ([]artifact.SignatureEvidence, error)
- func (r *Repository) TotalCalls() int
- func (r *Repository) Verify(_ context.Context, subject artifact.SignatureSubject, ...) (*artifact.VerificationResult, error)
- func (r *Repository) WriteEvidence(_ context.Context, pinned *artifact.PinnedReference, ...) ([]artifact.SignatureEvidence, error)
Constants ¶
const DefaultPageSize = 2
DefaultPageSize is the fake's list page size; it is small so tests exercise pagination.
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 ¶
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 ¶
func (f *FakeSigner) Sign(_ context.Context, subject artifact.SignatureSubject) (*artifact.EvidencePayload, error)
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 ¶
func (*FakeVerifier) Verify(_ context.Context, subject artifact.SignatureSubject, evidence []artifact.EvidenceBlob, policy artifact.VerificationPolicy) (*artifact.VerificationResult, error)
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 ¶
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 ¶
NewRecorder wraps the service.
func (*Recorder) FailPublications ¶
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 ¶
func (r *Recorder) Publish(ctx context.Context, request artifact.PublishRequest) (*artifact.OperationResult, error)
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 (*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 ¶
func (r *Repository) Delete(_ context.Context, pinned artifact.PinnedReference, options artifact.DeleteOptions) (*artifact.DeleteResult, error)
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 ¶
func (r *Repository) Inspect(_ context.Context, pinned artifact.PinnedReference) (*artifact.Inspection, error)
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 ¶
func (r *Repository) Lock(ctx context.Context, request artifact.LockRequest) (artifact.LockHandle, error)
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 ¶
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 ¶
func (r *Repository) OpenDocument(_ context.Context, pinned artifact.PinnedReference, role artifact.DocumentRole) (*artifact.DocumentStream, error)
OpenDocument implements artifact.Repository without touching the payload.
func (*Repository) Pin ¶
func (r *Repository) Pin(ctx context.Context, ref artifact.Ref) (artifact.PinnedReference, error)
Pin implements artifact.Repository. It acquires no lock and grants no trust.
func (*Repository) Publish ¶
func (r *Repository) Publish(ctx context.Context, prepared *artifact.PreparedArtifact, options artifact.PublishOptions) (*artifact.PublishResult, error)
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 ¶
func (r *Repository) Read(_ context.Context, pinned artifact.PinnedReference) (*artifact.Content, error)
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 ¶
RecordDigestOf returns the record digest a version reference currently points at.
func (*Repository) Resolve ¶
func (r *Repository) Resolve(_ context.Context, ref artifact.Ref) (artifact.PinnedReference, error)
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 ¶
func (r *Repository) Sign(ctx context.Context, subject artifact.SignatureSubject, signer artifact.Signer, _ artifact.SignOptions) ([]artifact.SignatureEvidence, error)
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 ¶
func (r *Repository) Verify(_ context.Context, subject artifact.SignatureSubject, policy artifact.VerificationPolicy) (*artifact.VerificationResult, error)
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 ¶
func (r *Repository) WriteEvidence(_ context.Context, pinned *artifact.PinnedReference, evidence []artifact.EvidenceBlob, _ artifact.LockHandle) ([]artifact.SignatureEvidence, error)
WriteEvidence implements artifact.EvidenceWriter.