Documentation ¶
Overview ¶
Package mock defines a fake storage implementation for use in testing.
Index ¶
- type ReadCall
- type Store
- func (s *Store) Abort(ctx context.Context, txn storage.Transaction)
- func (s *Store) AssertValid(t *testing.T)
- func (s *Store) Commit(ctx context.Context, txn storage.Transaction) error
- func (s *Store) DeletePolicy(ctx context.Context, txn storage.Transaction, name string) error
- func (s *Store) Errors() []error
- func (s *Store) GetPolicy(ctx context.Context, txn storage.Transaction, name string) ([]byte, error)
- func (s *Store) GetTransaction(id uint64) *Transaction
- func (s *Store) ListPolicies(ctx context.Context, txn storage.Transaction) ([]string, error)
- func (s *Store) NewTransaction(ctx context.Context, params ...storage.TransactionParams) (storage.Transaction, error)
- func (s *Store) Read(ctx context.Context, txn storage.Transaction, path storage.Path) (interface{}, error)
- func (s *Store) Register(ctx context.Context, txn storage.Transaction, config storage.TriggerConfig) (storage.TriggerHandle, error)
- func (s *Store) Reset()
- func (s *Store) Truncate(ctx context.Context, txn storage.Transaction, params storage.TransactionParams, ...) error
- func (s *Store) UpsertPolicy(ctx context.Context, txn storage.Transaction, name string, policy []byte) error
- func (s *Store) Write(ctx context.Context, txn storage.Transaction, op storage.PatchOp, ...) error
- type Transaction
- type WriteCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReadCall ¶
type ReadCall struct { Transaction *Transaction Path storage.Path Error error Safe bool }
ReadCall captures the parameters for a Read call
type Store ¶
type Store struct { Transactions []*Transaction Reads []*ReadCall Writes []*WriteCall // contains filtered or unexported fields }
Store is a mock storage.Store implementation for use in testing.
func NewWithData ¶ added in v0.14.0
NewWithData creates a store with some initial data
func (*Store) Abort ¶
func (s *Store) Abort(ctx context.Context, txn storage.Transaction)
Abort will abort the underlying transaction while also updating the mock Transaction
func (*Store) AssertValid ¶
AssertValid will raise an error with the provided testing.T if there are any errors on the store.
func (*Store) Commit ¶
Commit will commit the underlying transaction while also updating the mock Transaction
func (*Store) DeletePolicy ¶
DeletePolicy just shims the call to the underlying inmem store
func (*Store) Errors ¶
Errors returns a list of errors for each invalid state found. If any Transactions are invalid or reads/writes were unsafe an error will be returned for each problem.
func (*Store) GetPolicy ¶
func (s *Store) GetPolicy(ctx context.Context, txn storage.Transaction, name string) ([]byte, error)
GetPolicy just shims the call to the underlying inmem store
func (*Store) GetTransaction ¶
func (s *Store) GetTransaction(id uint64) *Transaction
GetTransaction will a transaction with a specific ID that was associated with this Store.
func (*Store) ListPolicies ¶
ListPolicies just shims the call to the underlying inmem store
func (*Store) NewTransaction ¶
func (s *Store) NewTransaction(ctx context.Context, params ...storage.TransactionParams) (storage.Transaction, error)
NewTransaction will create a new transaction on the underlying inmem store but wraps it with a mock Transaction. These are then tracked on the store.
func (*Store) Read ¶
func (s *Store) Read(ctx context.Context, txn storage.Transaction, path storage.Path) (interface{}, error)
Read will make a read from the underlying inmem store and add a new entry to the mock store Reads list. If there is an error are the read is unsafe it will be noted in the ReadCall.
func (*Store) Register ¶
func (s *Store) Register(ctx context.Context, txn storage.Transaction, config storage.TriggerConfig) (storage.TriggerHandle, error)
Register just shims the call to the underlying inmem store
func (*Store) Truncate ¶ added in v0.42.0
func (s *Store) Truncate(ctx context.Context, txn storage.Transaction, params storage.TransactionParams, it storage.Iterator) error
func (*Store) UpsertPolicy ¶
func (s *Store) UpsertPolicy(ctx context.Context, txn storage.Transaction, name string, policy []byte) error
UpsertPolicy just shims the call to the underlying inmem store
func (*Store) Write ¶
func (s *Store) Write(ctx context.Context, txn storage.Transaction, op storage.PatchOp, path storage.Path, value interface{}) error
Write will make a read from the underlying inmem store and add a new entry to the mock store Writes list. If there is an error are the write is unsafe it will be noted in the WriteCall.
type Transaction ¶
Transaction is a mock storage.Transaction implementation for use in testing. It uses an internal storage.Transaction pointer with some added functionality.
func (*Transaction) Validate ¶
func (t *Transaction) Validate() error
Validate returns an error if the transaction is in an invalid state