testing

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 7 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.

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

Jump to

Keyboard shortcuts

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