Documentation ¶
Overview ¶
Package teststore provides a common.Storage implementation for testing/mocking purposes.
A new teststore.TestStore can be obtained with teststore.New. Whenever one of the common.Storage methods is called, the implementation selects what function to call in the following order:
- If an override for that method was provided at construction time (via teststore.WithXXX()) or afterwards via SetOption, that override is used.
- If a substorage was provided at construction time (via teststore.WithSubstorage()) or afterwars via SetOption, the corresponding method in the substorage is used.
- If none of the above apply, the call panics with an error describing the unexpected call.
It's safe to call SetOption and the overrides from multiple goroutines, but it's the override's responsibility to ensure safety of whatever operation it executes.
Index ¶
- Variables
- type Option
- func WithClose(f func() error) Option
- func WithCompressor(f func() *compression.Config) Option
- func WithDelete(f func(common.DeletePrm) (common.DeleteRes, error)) Option
- func WithExists(f func(common.ExistsPrm) (common.ExistsRes, error)) Option
- func WithGet(f func(common.GetPrm) (common.GetRes, error)) Option
- func WithGetRange(f func(common.GetRangePrm) (common.GetRangeRes, error)) Option
- func WithInit(f func() error) Option
- func WithIterate(f func(common.IteratePrm) (common.IterateRes, error)) Option
- func WithOpen(f func(mode.ComponentMode) error) Option
- func WithPath(f func() string) Option
- func WithPut(f func(common.PutPrm) (common.PutRes, error)) Option
- func WithReportErrorFunc(f func(func(string, error))) Option
- func WithSetCompressor(f func(*compression.Config)) Option
- func WithSubstorage(st common.Storage) Option
- func WithType(f func() string) Option
- type TestStore
- func (s *TestStore) Close() error
- func (s *TestStore) Compressor() *compression.Config
- func (s *TestStore) Delete(ctx context.Context, req common.DeletePrm) (common.DeleteRes, error)
- func (s *TestStore) Exists(ctx context.Context, req common.ExistsPrm) (common.ExistsRes, error)
- func (s *TestStore) Get(ctx context.Context, req common.GetPrm) (common.GetRes, error)
- func (s *TestStore) GetRange(ctx context.Context, req common.GetRangePrm) (common.GetRangeRes, error)
- func (s *TestStore) Init() error
- func (s *TestStore) Iterate(ctx context.Context, req common.IteratePrm) (common.IterateRes, error)
- func (s *TestStore) ObjectsCount(ctx context.Context) (uint64, error)
- func (s *TestStore) Open(mod mode.ComponentMode) error
- func (s *TestStore) Path() string
- func (s *TestStore) Put(ctx context.Context, req common.PutPrm) (common.PutRes, error)
- func (s *TestStore) Rebuild(_ context.Context, _ common.RebuildPrm) (common.RebuildRes, error)
- func (s *TestStore) SetCompressor(cc *compression.Config)
- func (s *TestStore) SetOption(opt Option)
- func (s *TestStore) SetParentID(string)
- func (s *TestStore) SetReportErrorFunc(f func(string, error))
- func (s *TestStore) Type() string
Constants ¶
This section is empty.
Variables ¶
var ErrDiskExploded = errors.New("disk exploded")
ErrDiskExploded is a phony error which can be used for testing purposes to differentiate it from more common errors.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*cfg)
func WithCompressor ¶ added in v0.37.0
func WithCompressor(f func() *compression.Config) Option
func WithGetRange ¶
func WithGetRange(f func(common.GetRangePrm) (common.GetRangeRes, error)) Option
func WithIterate ¶
func WithIterate(f func(common.IteratePrm) (common.IterateRes, error)) Option
func WithReportErrorFunc ¶
func WithSetCompressor ¶
func WithSetCompressor(f func(*compression.Config)) Option
func WithSubstorage ¶
type TestStore ¶
type TestStore struct {
// contains filtered or unexported fields
}
TestStore is a common.Storage implementation for testing/mocking purposes.
func (*TestStore) Compressor ¶ added in v0.37.0
func (s *TestStore) Compressor() *compression.Config
func (*TestStore) GetRange ¶
func (s *TestStore) GetRange(ctx context.Context, req common.GetRangePrm) (common.GetRangeRes, error)
func (*TestStore) Iterate ¶
func (s *TestStore) Iterate(ctx context.Context, req common.IteratePrm) (common.IterateRes, error)
func (*TestStore) ObjectsCount ¶ added in v0.39.0
func (*TestStore) Rebuild ¶ added in v0.38.0
func (s *TestStore) Rebuild(_ context.Context, _ common.RebuildPrm) (common.RebuildRes, error)
func (*TestStore) SetCompressor ¶
func (s *TestStore) SetCompressor(cc *compression.Config)
func (*TestStore) SetOption ¶
SetOption overrides an option of an existing teststore.TestStore. This is useful for overriding methods during a test so that different behaviors are simulated.