teststore

package
v0.42.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

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:

  1. If an override for that method was provided at construction time (via teststore.WithXXX()) or afterwards via SetOption, that override is used.
  2. If a substorage was provided at construction time (via teststore.WithSubstorage()) or afterwars via SetOption, the corresponding method in the substorage is used.
  3. 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

Constants

This section is empty.

Variables

View Source
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 WithClose

func WithClose(f func() error) Option

func WithCompressor added in v0.37.0

func WithCompressor(f func() *compression.Config) Option

func WithDelete

func WithDelete(f func(common.DeletePrm) (common.DeleteRes, error)) Option

func WithExists

func WithExists(f func(common.ExistsPrm) (common.ExistsRes, error)) Option

func WithGet

func WithGet(f func(common.GetPrm) (common.GetRes, error)) Option

func WithGetRange

func WithGetRange(f func(common.GetRangePrm) (common.GetRangeRes, error)) Option

func WithInit

func WithInit(f func() error) Option

func WithIterate

func WithIterate(f func(common.IteratePrm) (common.IterateRes, error)) Option

func WithOpen

func WithOpen(f func(mode.ComponentMode) error) Option

func WithPath

func WithPath(f func() string) Option

func WithPut

func WithPut(f func(common.PutPrm) (common.PutRes, error)) Option

func WithReportErrorFunc

func WithReportErrorFunc(f func(func(string, error))) Option

func WithSetCompressor

func WithSetCompressor(f func(*compression.Config)) Option

func WithSubstorage

func WithSubstorage(st common.Storage) Option

func WithType

func WithType(f func() string) Option

type TestStore

type TestStore struct {
	// contains filtered or unexported fields
}

TestStore is a common.Storage implementation for testing/mocking purposes.

func New

func New(opts ...Option) *TestStore

New returns a teststore.TestStore from the given options.

func (*TestStore) Close

func (s *TestStore) Close() error

func (*TestStore) Compressor added in v0.37.0

func (s *TestStore) Compressor() *compression.Config

func (*TestStore) Delete

func (s *TestStore) Delete(ctx context.Context, req common.DeletePrm) (common.DeleteRes, error)

func (*TestStore) Exists

func (s *TestStore) Exists(ctx context.Context, req common.ExistsPrm) (common.ExistsRes, error)

func (*TestStore) Get

func (s *TestStore) Get(ctx context.Context, req common.GetPrm) (common.GetRes, error)

func (*TestStore) GetRange

func (*TestStore) Init

func (s *TestStore) Init() 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 (s *TestStore) ObjectsCount(ctx context.Context) (uint64, error)

func (*TestStore) Open

func (s *TestStore) Open(mod mode.ComponentMode) error

func (*TestStore) Path

func (s *TestStore) Path() string

func (*TestStore) Put

func (s *TestStore) Put(ctx context.Context, req common.PutPrm) (common.PutRes, error)

func (*TestStore) Rebuild added in v0.38.0

func (*TestStore) SetCompressor

func (s *TestStore) SetCompressor(cc *compression.Config)

func (*TestStore) SetOption

func (s *TestStore) SetOption(opt Option)

SetOption overrides an option of an existing teststore.TestStore. This is useful for overriding methods during a test so that different behaviors are simulated.

func (*TestStore) SetParentID added in v0.37.0

func (s *TestStore) SetParentID(string)

func (*TestStore) SetReportErrorFunc

func (s *TestStore) SetReportErrorFunc(f func(string, error))

func (*TestStore) Type

func (s *TestStore) Type() string

Jump to

Keyboard shortcuts

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