Documentation
¶
Overview ¶
Package testing provides test utilities for the keystore package. It includes MockKeyStore for unit testing modules that depend on app.KeyStore.
Index ¶
- func AssertKeyNotFound(t *testing.T, ks app.KeyStore, name string)
- func AssertPrivateKeyAvailable(t *testing.T, ks app.KeyStore, name string)
- func AssertPublicKeyAvailable(t *testing.T, ks app.KeyStore, name string)
- type MockKeyStore
- func (m *MockKeyStore) PrivateKey(name string) (*rsa.PrivateKey, error)
- func (m *MockKeyStore) PublicKey(name string) (*rsa.PublicKey, error)
- func (m *MockKeyStore) WithPrivateKey(name string, key *rsa.PrivateKey) *MockKeyStore
- func (m *MockKeyStore) WithPrivateKeyError(err error) *MockKeyStore
- func (m *MockKeyStore) WithPublicKey(name string, key *rsa.PublicKey) *MockKeyStore
- func (m *MockKeyStore) WithPublicKeyError(err error) *MockKeyStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertKeyNotFound ¶
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 ¶
AssertPrivateKeyAvailable verifies that a private 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.