trovetest

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package trovetest provides testing utilities for Trove storage drivers.

The primary entry point is RunDriverSuite, which runs a comprehensive conformance test suite against any driver.Driver implementation. All Trove drivers must pass this suite to be considered conformant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertObjectEquals

func AssertObjectEquals(t *testing.T, expected, actual *driver.ObjectInfo)

AssertObjectEquals asserts that two ObjectInfo values are equal on the fields that matter for conformance (ignoring timing fields).

func RandomData

func RandomData(size int) []byte

RandomData generates random bytes of the specified size.

func ReadAll

func ReadAll(t *testing.T, reader *driver.ObjectReader) []byte

ReadAll reads all bytes from an ObjectReader and closes it.

func RunDriverSuite

func RunDriverSuite(t *testing.T, factory func(t *testing.T) driver.Driver)

RunDriverSuite runs the full conformance test suite against a driver. The factory function must return a fresh, opened driver instance for each test. Every Trove driver must pass this suite.

The not-found cases assert against the sentinels in the driver package rather than merely asserting that an error occurred, because classifying a missing object is part of the driver contract — see the error contract in the driver package documentation.

Where a backend cannot distinguish a missing object from a missing bucket (an object read against a bucket that does not exist reports differently across providers), the suite asserts only the general ErrNotFound. The per-driver tests pin the specific sentinel.

func TestObject

func TestObject(key string, data []byte) (string, io.Reader)

TestObject creates a test object key and reader from the given data.

Types

type MockDriver

type MockDriver struct {
	NameFunc         func() string
	OpenFunc         func(ctx context.Context, dsn string, opts ...driver.Option) error
	CloseFunc        func(ctx context.Context) error
	PingFunc         func(ctx context.Context) error
	PutFunc          func(ctx context.Context, bucket, key string, r io.Reader, opts ...driver.PutOption) (*driver.ObjectInfo, error)
	GetFunc          func(ctx context.Context, bucket, key string, opts ...driver.GetOption) (*driver.ObjectReader, error)
	DeleteFunc       func(ctx context.Context, bucket, key string, opts ...driver.DeleteOption) error
	HeadFunc         func(ctx context.Context, bucket, key string) (*driver.ObjectInfo, error)
	ListFunc         func(ctx context.Context, bucket string, opts ...driver.ListOption) (*driver.ObjectIterator, error)
	CopyFunc         func(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string, opts ...driver.CopyOption) (*driver.ObjectInfo, error)
	CreateBucketFunc func(ctx context.Context, name string, opts ...driver.BucketOption) error
	DeleteBucketFunc func(ctx context.Context, name string) error
	ListBucketsFunc  func(ctx context.Context) ([]driver.BucketInfo, error)
}

MockDriver is a configurable mock driver for unit testing. Set the function fields to control behavior per method.

func (*MockDriver) Close

func (m *MockDriver) Close(ctx context.Context) error

Close delegates to CloseFunc or returns nil.

func (*MockDriver) Copy

func (m *MockDriver) Copy(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string, opts ...driver.CopyOption) (*driver.ObjectInfo, error)

Copy delegates to CopyFunc or returns nil.

func (*MockDriver) CreateBucket

func (m *MockDriver) CreateBucket(ctx context.Context, name string, opts ...driver.BucketOption) error

CreateBucket delegates to CreateBucketFunc or returns nil.

func (*MockDriver) Delete

func (m *MockDriver) Delete(ctx context.Context, bucket, key string, opts ...driver.DeleteOption) error

Delete delegates to DeleteFunc or returns nil.

func (*MockDriver) DeleteBucket

func (m *MockDriver) DeleteBucket(ctx context.Context, name string) error

DeleteBucket delegates to DeleteBucketFunc or returns nil.

func (*MockDriver) Get

func (m *MockDriver) Get(ctx context.Context, bucket, key string, opts ...driver.GetOption) (*driver.ObjectReader, error)

Get delegates to GetFunc or returns nil.

func (*MockDriver) Head

func (m *MockDriver) Head(ctx context.Context, bucket, key string) (*driver.ObjectInfo, error)

Head delegates to HeadFunc or returns nil.

func (*MockDriver) List

func (m *MockDriver) List(ctx context.Context, bucket string, opts ...driver.ListOption) (*driver.ObjectIterator, error)

List delegates to ListFunc or returns an empty iterator.

func (*MockDriver) ListBuckets

func (m *MockDriver) ListBuckets(ctx context.Context) ([]driver.BucketInfo, error)

ListBuckets delegates to ListBucketsFunc or returns empty.

func (*MockDriver) Name

func (m *MockDriver) Name() string

Name returns "mock" or delegates to NameFunc.

func (*MockDriver) Open

func (m *MockDriver) Open(ctx context.Context, dsn string, opts ...driver.Option) error

Open delegates to OpenFunc or returns nil.

func (*MockDriver) Ping

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

Ping delegates to PingFunc or returns nil.

func (*MockDriver) Put

func (m *MockDriver) Put(ctx context.Context, bucket, key string, r io.Reader, opts ...driver.PutOption) (*driver.ObjectInfo, error)

Put delegates to PutFunc or returns nil.

Jump to

Keyboard shortcuts

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