mock

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package mock defines a fake storage implementation for use in testing.

Index

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 New

func New() *Store

New creates a new mock Store

func NewWithData added in v0.14.0

func NewWithData(data map[string]interface{}) *Store

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

func (s *Store) AssertValid(t *testing.T)

AssertValid will raise an error with the provided testing.T if there are any errors on the store.

func (*Store) Commit

func (s *Store) Commit(ctx context.Context, txn storage.Transaction) error

Commit will commit the underlying transaction while also updating the mock Transaction

func (*Store) DeletePolicy

func (s *Store) DeletePolicy(ctx context.Context, txn storage.Transaction, name string) error

DeletePolicy just shims the call to the underlying inmem store

func (*Store) Errors

func (s *Store) Errors() []error

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

func (s *Store) ListPolicies(ctx context.Context, txn storage.Transaction) ([]string, error)

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

Register just shims the call to the underlying inmem store

func (*Store) Reset

func (s *Store) Reset()

Reset the store

func (*Store) Truncate added in v0.42.0

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

type Transaction struct {
	Committed int
	Aborted   int
	// contains filtered or unexported fields
}

Transaction is a mock storage.Transaction implementation for use in testing. It uses an internal storage.Transaction pointer with some added functionality.

func (*Transaction) ID

func (t *Transaction) ID() uint64

ID returns the underlying transaction ID

func (*Transaction) Validate

func (t *Transaction) Validate() error

Validate returns an error if the transaction is in an invalid state

type WriteCall

type WriteCall struct {
	Transaction *Transaction
	Op          storage.PatchOp
	Path        storage.Path
	Error       error
	Safe        bool
}

WriteCall captures the parameters for a write call

Jump to

Keyboard shortcuts

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