testing

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testing provides test utilities for the keystore package. It includes MockKeyStore for unit testing modules that depend on app.KeyStore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertKeyNotFound

func AssertKeyNotFound(t *testing.T, ks app.KeyStore, name string)

AssertKeyNotFound verifies that retrieving a key with the given name is a miss on both PublicKey and PrivateKey: each lookup must return a non-nil error AND no key. Note that this does not distinguish between "key name not found" and "no private key configured" — error-ness alone is all it reads from the error.

A stray key is reported by dynamic TYPE only, never by value (ADR-102).

An unexpectedly FOUND public key — an error-free lookup, or a key handed back alongside the error — aborts the caller's test rather than recording a failure and continuing: the private-key assertion that follows would otherwise run against a keystore already known to be in the wrong state, and its result — pass or fail — says nothing useful once the first lookup has produced a key (ADR-101).

func AssertPrivateKeyAvailable

func AssertPrivateKeyAvailable(t *testing.T, ks app.KeyStore, name string)

AssertPrivateKeyAvailable verifies that a private key with the given name can be successfully retrieved from the KeyStore.

func AssertPublicKeyAvailable

func AssertPublicKeyAvailable(t *testing.T, ks app.KeyStore, name string)

AssertPublicKeyAvailable verifies that a public key with the given name can be successfully retrieved from the KeyStore.

func AssertSecretAvailable added in v0.35.0

func AssertSecretAvailable(t *testing.T, ks app.KeyStore, name string)

AssertSecretAvailable verifies that a non-empty symmetric secret with the given name can be successfully retrieved from the KeyStore.

Types

type MockKeyStore

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

MockKeyStore implements app.KeyStore for unit testing. Use the fluent builder methods to configure keys and error behavior.

Example:

mock := kstest.NewMockKeyStore().
    WithPublicKey("signing", pubKey).
    WithPrivateKey("signing", privKey)

deps := &app.ModuleDeps{
    KeyStore: mock,
}

func NewMockKeyStore

func NewMockKeyStore() *MockKeyStore

NewMockKeyStore creates an empty MockKeyStore.

func (*MockKeyStore) Generations added in v0.63.0

func (m *MockKeyStore) Generations(logical string) []keystore.Generation

Generations implements keystore.FamilyEnumerator.

func (*MockKeyStore) PrivateKey

func (m *MockKeyStore) PrivateKey(name string) (*rsa.PrivateKey, error)

PrivateKey implements app.KeyStore.

func (*MockKeyStore) PublicKey

func (m *MockKeyStore) PublicKey(name string) (*rsa.PublicKey, error)

PublicKey implements app.KeyStore.

func (*MockKeyStore) RecordResolution added in v0.63.0

func (m *MockKeyStore) RecordResolution(entry, role string)

RecordResolution implements keystore.RoleRecorder: the mock remembers every (entry, role) a startup resolution tagged, in call order, so a test can assert which entries the module under test claimed and under which role.

func (*MockKeyStore) Recorded added in v0.63.0

func (m *MockKeyStore) Recorded() [][2]string

Recorded returns the (entry, role) pairs RecordResolution received, in order.

func (*MockKeyStore) Secret added in v0.35.0

func (m *MockKeyStore) Secret(name string) ([]byte, error)

Secret implements app.KeyStore. It returns a defensive copy, mirroring the real store so tests exercise the same ownership contract.

func (*MockKeyStore) WithGeneration added in v0.63.0

func (m *MockKeyStore) WithGeneration(logical, version string, role keystore.Role) *MockKeyStore

WithGeneration declares one provisioned generation of a Logical kid. The mock applies no grammar, so a test controls the exact accept set the module under test sees, but it keeps the FamilyEnumerator ordering contract: Generations returns ascending versions whatever the declaration order. Pair it with WithPublicKey and friends on the generation's Kid() when the module also fetches material.

func (*MockKeyStore) WithPrivateKey

func (m *MockKeyStore) WithPrivateKey(name string, key *rsa.PrivateKey) *MockKeyStore

WithPrivateKey adds a private key for the given name.

func (*MockKeyStore) WithPrivateKeyError

func (m *MockKeyStore) WithPrivateKeyError(err error) *MockKeyStore

WithPrivateKeyError configures all PrivateKey calls to return this error.

func (*MockKeyStore) WithPublicKey

func (m *MockKeyStore) WithPublicKey(name string, key *rsa.PublicKey) *MockKeyStore

WithPublicKey adds a public key for the given name.

func (*MockKeyStore) WithPublicKeyError

func (m *MockKeyStore) WithPublicKeyError(err error) *MockKeyStore

WithPublicKeyError configures all PublicKey calls to return this error.

func (*MockKeyStore) WithSecret added in v0.35.0

func (m *MockKeyStore) WithSecret(name string, secret []byte) *MockKeyStore

WithSecret adds raw symmetric key material for the given name. The slice is copied so later caller mutations do not bleed into the mock.

func (*MockKeyStore) WithSecretError added in v0.35.0

func (m *MockKeyStore) WithSecretError(err error) *MockKeyStore

WithSecretError configures all Secret calls to return this error.

Jump to

Keyboard shortcuts

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