kvtest

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package kvtest provides a mock KV driver and conformance test suite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BenchStore

func BenchStore(b *testing.B, opts ...kv.Option) *kv.Store

BenchStore creates a Store with the mock driver for benchmarks.

func PopulateStore

func PopulateStore(b *testing.B, store *kv.Store, n int)

PopulateStore pre-populates n keys formatted as "key:0" → "value:0", etc.

func RunCollectionSuite added in v1.6.1

func RunCollectionSuite(t *testing.T, drv driver.Driver)

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

func RunConformanceSuite(t *testing.T, drv driver.Driver)

RunConformanceSuite runs the full conformance test suite against a KV driver. Every driver must pass all tests in this suite.

func SetupStore

func SetupStore(t *testing.T, opts ...kv.Option) *kv.Store

SetupStore creates a Store with the mock driver for testing.

func SetupTwoStores

func SetupTwoStores(t *testing.T) (primary *kv.Store, replica *kv.Store)

SetupTwoStores creates two independent stores backed by separate mock drivers. Useful for CRDT syncer tests that need primary/replica pairs.

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) Delete

func (m *MockDriver) Delete(_ context.Context, keys ...string) (int64, error)

func (*MockDriver) Exists

func (m *MockDriver) Exists(_ context.Context, keys ...string) (int64, error)

func (*MockDriver) Expire

func (m *MockDriver) Expire(_ context.Context, key string, ttl time.Duration) error

func (*MockDriver) Get

func (m *MockDriver) Get(_ context.Context, key string) ([]byte, error)

func (*MockDriver) Info

func (m *MockDriver) Info() driver.DriverInfo

func (*MockDriver) MGet

func (m *MockDriver) MGet(_ context.Context, keys []string) ([][]byte, error)

func (*MockDriver) MSet

func (m *MockDriver) MSet(_ context.Context, pairs map[string][]byte, ttl time.Duration) error

func (*MockDriver) Name

func (m *MockDriver) Name() string

func (*MockDriver) Open

func (m *MockDriver) Open(_ context.Context, _ string, _ ...driver.Option) error

func (*MockDriver) Ping

func (m *MockDriver) Ping(_ context.Context) error

func (*MockDriver) Scan

func (m *MockDriver) Scan(_ context.Context, pattern string, fn func(key string) error) error

func (*MockDriver) Set

func (m *MockDriver) Set(_ context.Context, key string, value []byte, ttl time.Duration) error

func (*MockDriver) SetNX

func (m *MockDriver) SetNX(_ context.Context, key string, value []byte, ttl time.Duration) (bool, error)

func (*MockDriver) SetXX

func (m *MockDriver) SetXX(_ context.Context, key string, value []byte, ttl time.Duration) (bool, error)

func (*MockDriver) TTL

func (m *MockDriver) TTL(_ context.Context, key string) (time.Duration, error)

Jump to

Keyboard shortcuts

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