testing

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 8 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 returns an error from both PublicKey and PrivateKey. Note that this does not distinguish between "key name not found" and "no private key configured" — it only asserts that both lookups return a non-nil error.

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) 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) 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) 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