Documentation
¶
Overview ¶
Package storetest provides test doubles for store.ObjectStore.
Index ¶
- func AssertRangeGetterConformance(t *testing.T, s ObjectStore)
- type FaultHook
- type FaultStore
- type MemStore
- func (m *MemStore) Delete(_ context.Context, key string) error
- func (m *MemStore) Exists(_ context.Context, key string) (bool, error)
- func (m *MemStore) Flush(_ context.Context) error
- func (m *MemStore) Get(_ context.Context, key string) ([]byte, error)
- func (m *MemStore) Len() int
- func (m *MemStore) List(_ context.Context, prefix string) ([]string, error)
- func (m *MemStore) Put(_ context.Context, key string, data []byte) error
- func (m *MemStore) Size(_ context.Context, key string) (int64, error)
- func (m *MemStore) TotalSize(_ context.Context) (int64, error)
- type ObjectStore
- type RangeGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertRangeGetterConformance ¶ added in v1.18.0
func AssertRangeGetterConformance(t *testing.T, s ObjectStore)
assertRangeGetterConformance is the shared contract every RangeGetter must satisfy, so the backends cannot drift apart. Each is exercised against a live instance of its own backend. AssertRangeGetterConformance is exported so every backend package can hold itself to the same contract.
Types ¶
type FaultHook ¶
FaultHook decides whether a FaultStore call should fail. key is the object key (List passes its prefix instead), and callNum is the 1-indexed count of calls to that method so far, including the current one. A nil return lets the call proceed to the wrapped store.
func AlwaysFail ¶
AlwaysFail returns a FaultHook that fails every call to that method.
type FaultStore ¶
type FaultStore struct {
ObjectStore
FailGet FaultHook
FailPut FaultHook
FailList FaultHook
// contains filtered or unexported fields
}
FaultStore wraps an ObjectStore and lets tests inject failures into Get, Put, or List independently of what the backend itself would do — simulating a network blip, a permission error, or a partial outage. Each hook is optional; a nil hook means that method always passes through.
FaultStore is safe for concurrent use.
type MemStore ¶ added in v1.18.0
type MemStore struct {
// contains filtered or unexported fields
}
MemStore is an in-memory ObjectStore for tests. It is safe for concurrent use, so it can stand in for a real backend under -race.
func NewMemStore ¶ added in v1.18.0
func NewMemStore() *MemStore
NewMemStore returns an empty in-memory store.
type ObjectStore ¶
type ObjectStore interface {
Put(ctx context.Context, key string, data []byte) error
Get(ctx context.Context, key string) ([]byte, error)
Exists(ctx context.Context, key string) (bool, error)
Delete(ctx context.Context, key string) error
List(ctx context.Context, prefix string) ([]string, error)
Size(ctx context.Context, key string) (int64, error)
TotalSize(ctx context.Context) (int64, error)
Flush(ctx context.Context) error
}
ObjectStore mirrors the method set of store.ObjectStore. It is declared independently, rather than imported, so this package can also be used from pkg/store's own internal (package store) tests without an import cycle — any store.ObjectStore implementation satisfies this interface structurally.
type RangeGetter ¶ added in v1.18.0
type RangeGetter interface {
GetRange(ctx context.Context, key string, offset, length int64) ([]byte, error)
}
RangeGetter mirrors store.RangeGetter. It is redeclared here, rather than imported, for the same reason ObjectStore is: pkg/store's own internal tests import this package, so depending on pkg/store would make the test binary import itself.