Documentation
¶
Overview ¶
Package kvtest provides a mock KV driver and conformance test suite.
Index ¶
- func BenchStore(b *testing.B, opts ...kv.Option) *kv.Store
- func PopulateStore(b *testing.B, store *kv.Store, n int)
- func RunCollectionSuite(t *testing.T, drv driver.Driver)
- func RunConformanceSuite(t *testing.T, drv driver.Driver)
- func SetupStore(t *testing.T, opts ...kv.Option) *kv.Store
- func SetupTwoStores(t *testing.T) (primary *kv.Store, replica *kv.Store)
- type MockDriver
- func (m *MockDriver) Close() error
- func (m *MockDriver) Delete(_ context.Context, keys ...string) (int64, error)
- func (m *MockDriver) Exists(_ context.Context, keys ...string) (int64, error)
- func (m *MockDriver) Expire(_ context.Context, key string, ttl time.Duration) error
- func (m *MockDriver) Get(_ context.Context, key string) ([]byte, error)
- func (m *MockDriver) Info() driver.DriverInfo
- func (m *MockDriver) MGet(_ context.Context, keys []string) ([][]byte, error)
- func (m *MockDriver) MSet(_ context.Context, pairs map[string][]byte, ttl time.Duration) error
- func (m *MockDriver) Name() string
- func (m *MockDriver) Open(_ context.Context, _ string, _ ...driver.Option) error
- func (m *MockDriver) Ping(_ context.Context) error
- func (m *MockDriver) Scan(_ context.Context, pattern string, fn func(key string) error) error
- func (m *MockDriver) Set(_ context.Context, key string, value []byte, ttl time.Duration) error
- func (m *MockDriver) SetNX(_ context.Context, key string, value []byte, ttl time.Duration) (bool, error)
- func (m *MockDriver) SetXX(_ context.Context, key string, value []byte, ttl time.Duration) (bool, error)
- func (m *MockDriver) TTL(_ context.Context, key string) (time.Duration, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BenchStore ¶
BenchStore creates a Store with the mock driver for benchmarks.
func PopulateStore ¶
PopulateStore pre-populates n keys formatted as "key:0" → "value:0", etc.
func RunCollectionSuite ¶ added in v1.6.1
RunCollectionSuite exercises the optional sorted-set, set, and hash capabilities.
It is separate from the conformance suite because these are optional: a driver that does not advertise a capability skips that section rather than failing. What it does enforce is that advertising and providing agree — a driver claiming CapSortedSet in Info() must implement SortedSetDriver, because a capability flag nothing can consume is worse than no flag at all.
func RunConformanceSuite ¶
RunConformanceSuite runs the full conformance test suite against a KV driver. Every driver must pass all tests in this suite.
func SetupStore ¶
SetupStore creates a Store with the mock driver for testing.
Types ¶
type MockDriver ¶
type MockDriver struct {
// contains filtered or unexported fields
}
MockDriver is an in-memory KV driver for unit testing. It implements all optional driver interfaces.
func NewMockDriver ¶
func NewMockDriver() *MockDriver
NewMockDriver creates a new in-memory mock driver.
func (*MockDriver) Close ¶
func (m *MockDriver) Close() error
func (*MockDriver) Info ¶
func (m *MockDriver) Info() driver.DriverInfo
func (*MockDriver) Name ¶
func (m *MockDriver) Name() string