storefx

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package storefx supplies Store fixtures for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hashes

func Hashes() domain.HashRegistry

Hashes returns a HashRegistry suitable for tests. sha256 is real; blake3 is registered as an sha256-backed stub so tests that set ContentHasher: HashBLAKE3 do not need to pull in a blake3 library. Tests that care about a specific algorithm register their own.

func Init

func Init(t testing.TB, opts ...core.StoreOption) core.Store

Init: fresh Store on localfs + in-memory sqlite index + sha256. Caller opts append to (and can override) defaults.

func InitEncryptedOn

func InitEncryptedOn(t testing.TB, drv driver.Driver, pass string, extra ...core.StoreOption)

InitEncryptedOn bootstraps an encrypted Store on a caller-provided driver. A fresh in-memory index is wired up internally, then discarded — the caller's intent with this helper is to seed an on-disk Location and immediately exercise OpenStore against it (e.g. to verify the full bootstrap path on a deliberately damaged Location). For tests that want to keep using the same (drv, idx) pair across init+reopen, see InitEncrypted + Reopener.Open.

func InitOn

func InitOn(t testing.TB, drv driver.Driver, opts ...core.StoreOption) core.Store

InitOn wires Init around a caller-provided driver. Caller also owns the index — pass core.WithStoreIndex explicitly.

func InitPlainOn

func InitPlainOn(t testing.TB, drv driver.Driver, extra ...core.StoreOption)

InitPlainOn is the Plain-DEK counterpart of InitEncryptedOn: bootstrap on a caller-supplied driver with a discarded index, no passphrase. Use to seed a Location for subsequent OpenStore scenarios that do not need a Reopener.

func InitWithRoot

func InitWithRoot(t testing.TB, opts ...core.StoreOption) (core.Store, string)

InitWithRoot is Init plus the driver root for on-disk inspection.

func OpenOn

func OpenOn(t testing.TB, drv driver.Driver, extra ...core.StoreOption) core.Store

OpenOn is the fatal variant of TryOpenOn: it calls t.Fatalf when OpenStore returns an error and returns just the Store on success.

func Payload

func Payload(content string) domain.Artifact

Payload wraps a string as a domain.Artifact body.

func RecordingPP

func RecordingPP(pass string, log *[]core.PassphraseHint) core.PassphraseProvider

RecordingPP returns the configured passphrase but records every PassphraseHint it sees into log. Use when the test asserts on Reason / StoreID values that the engine threads through the provider call.

log is appended to, not reset — pass a fresh slice per test.

func ScriptedPP

func ScriptedPP(values ...string) core.PassphraseProvider

ScriptedPP returns a different passphrase per call, driven by values. Use to script provider behaviour across two-call methods (RotateKEK invokes the provider twice — current then new). Returns an error after the script is exhausted.

func StaticPP

func StaticPP(pass string) core.PassphraseProvider

StaticPP is a one-line PassphraseProvider for tests: returns the same passphrase regardless of hint. Use when the test only needs one valid credential.

func TryOpenOn

func TryOpenOn(t testing.TB, drv driver.Driver, extra ...core.StoreOption) (core.Store, error)

TryOpenOn calls core.OpenStore on a caller-supplied driver with a fresh in-memory index and the standard test hash registry. Returns the (Store, error) pair so the caller can assert on the failure mode itself — fatal-on-failure callers should use OpenOn.

Types

type OnDisk

type OnDisk struct {
	Root string
}

OnDisk wraps a localfs root for physical inspection. Construct via OnDiskAt(root) or via the Reopener.OnDisk() shortcut.

Methods that take *testing.TB call t.Fatalf on unexpected I/O — a stat-error means the test's setup is wrong, not the engine's behaviour.

func OnDiskAt

func OnDiskAt(root string) OnDisk

OnDiskAt returns an OnDisk inspector rooted at the given path.

func (OnDisk) BlobCount

func (d OnDisk) BlobCount() int

BlobCount returns the number of regular files under <root>/blobs/. A missing blobs/ directory counts as zero.

func (OnDisk) BlobFiles

func (d OnDisk) BlobFiles() []string

BlobFiles returns the absolute paths of every regular file under <root>/blobs/. Order is filepath.Walk-driven (lexicographic). A missing blobs/ directory yields an empty slice.

func (OnDisk) ManifestExists

func (d OnDisk) ManifestExists(id domain.ArtifactID) bool

ManifestExists reports whether the manifest file for id is present on disk. Used after Delete to assert physical removal.

func (OnDisk) ManifestPath

func (d OnDisk) ManifestPath(id domain.ArtifactID) string

ManifestPath returns the on-disk path of the manifest file for the given ArtifactID, computed via the same blobpath helper that core uses internally. Tests use this to assert manifest presence or absence without re-implementing the shard rule.

Returns an empty string if blobpath rejects the ID — callers should treat that as a test setup error and fail explicitly.

func (OnDisk) ReadManifest

func (d OnDisk) ReadManifest(t testing.TB, id domain.ArtifactID) domain.Manifest

ReadManifest decodes the manifest file at id. Used to inspect fields that Walk does not return (LayoutHeader, InlineBlob, Pipeline, Metadata) — the index is a routing layer, not a source of truth for manifest content.

Calls t.Fatalf on read or decode failure.

func (OnDisk) StagingFiles

func (d OnDisk) StagingFiles() []string

StagingFiles returns regular files under <root>/system.state/staging/. A non-empty result after a completed operation indicates a leak.

type Reopener

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

Reopener captures the (Driver, StoreIndex) pair so a test can reopen the same Location across the engine boundary. drv and idx outlive any individual core.Store; the Reopener exists for scenarios where the test sequence is "Init → close store → reopen with different options" — common in encrypted-Store flows where the second open uses AutoUnlock or a new passphrase.

Reopener does NOT register cleanup for drv/idx — those are already cleaned up by the underlying driverfx / indexfx fixtures against t.

func InitEncrypted

func InitEncrypted(t testing.TB, pass string, extra ...core.StoreOption) (core.Store, *Reopener)

InitEncrypted bootstraps a fresh encrypted Store with the given passphrase and returns a Reopener. The Store is fully Unlocked after Init (per the Plain-DEK→Encrypted transition described in core/lifecycle.go's InitStore).

extra options are appended to the engine's defaults; pass core.WithKDFParams or core.WithConfig as needed.

func InitEncryptedLocked

func InitEncryptedLocked(t testing.TB, pass string, extra ...core.StoreOption) (core.Store, *Reopener)

InitEncryptedLocked bootstraps an encrypted Store and reopens it WITHOUT AutoUnlock so the returned Store is in StateLocked. The PassphraseProvider configured on the second open uses the same passphrase — tests that need a different provider can replace it via Reopener.Open with WithPassphrase override.

func InitPlain

func InitPlain(t testing.TB, extra ...core.StoreOption) (core.Store, *Reopener)

InitPlain bootstraps a fresh Plain Store and returns a Reopener bound to the same (drv, idx) so the test can reopen the Location later. Use whenever the test exercises a reopen-flow; for single-Init tests, plain Init/InitWithRoot remain shorter.

func (*Reopener) Driver

func (r *Reopener) Driver() driver.Driver

Driver returns the underlying driver. Tests use this for direct on-disk inspection (descriptor.Read, raw drv.Get on a known path).

func (*Reopener) Index

func (r *Reopener) Index() core.StoreIndex

Index returns the captured StoreIndex.

func (*Reopener) Open

func (r *Reopener) Open(t testing.TB, extra ...core.StoreOption) core.Store

Open reopens the captured Location. WithStoreIndex and WithHashRegistry are filled in automatically; pass any other option (WithPassphrase, WithAutoUnlock, WithConfig, ...) through extra. Calls t.Fatalf on failure.

func (*Reopener) Root

func (r *Reopener) Root() string

Root returns the localfs root if the underlying driver is a localfs.Driver; empty string otherwise. Used by tests that need to walk the on-disk tree directly.

func (*Reopener) TryOpen

func (r *Reopener) TryOpen(t testing.TB, extra ...core.StoreOption) (core.Store, error)

TryOpen is the non-fatal variant of Open: it returns the error instead of t.Fatalf. Use when the test's assertion is on the failure mode itself (wrong passphrase, ConfigMismatch, ...).

Jump to

Keyboard shortcuts

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