storagetesting

package
v0.3.0-pre0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package storagetesting is used for testing Storage implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertConnectionInfoRoundTrips

func AssertConnectionInfoRoundTrips(ctx context.Context, t *testing.T, s storage.Storage)

AssertConnectionInfoRoundTrips verifies that the ConnectionInfo returned by a given storage can be used to create equivalent storage

func AssertGetBlock

func AssertGetBlock(ctx context.Context, t *testing.T, s storage.Storage, block string, expected []byte)

AssertGetBlock asserts that the specified storage block has correct content.

func AssertGetBlockNotFound

func AssertGetBlockNotFound(ctx context.Context, t *testing.T, s storage.Storage, block string)

AssertGetBlockNotFound asserts that GetBlock() for specified storage block returns ErrBlockNotFound.

func AssertInvalidOffsetLength

func AssertInvalidOffsetLength(ctx context.Context, t *testing.T, s storage.Storage, block string, offset, length int64)

AssertInvalidOffsetLength verifies that the given combination of (offset,length) fails on GetBlock()

func AssertListResults

func AssertListResults(ctx context.Context, t *testing.T, s storage.Storage, prefix string, want ...string)

AssertListResults asserts that the list results with given prefix return the specified list of names in order.

func NewMapStorage

func NewMapStorage(data map[string][]byte, keyTime map[string]time.Time, timeNow func() time.Time) storage.Storage

NewMapStorage returns an implementation of Storage backed by the contents of given map. Used primarily for testing.

func VerifyStorage

func VerifyStorage(ctx context.Context, t *testing.T, r storage.Storage)

VerifyStorage verifies the behavior of the specified storage.

Types

type Fault

type Fault struct {
	Repeat      int           // how many times to repeat this fault
	Sleep       time.Duration // sleep before returning
	ErrCallback func() error
	WaitFor     chan struct{} // waits until the given channel is closed before returning
	Err         error         // error to return (can be nil in combination with Sleep and WaitFor)
}

Fault describes the behavior of a single fault.

type FaultyStorage

type FaultyStorage struct {
	Base   storage.Storage
	Faults map[string][]*Fault
	// contains filtered or unexported fields
}

FaultyStorage implements fault injection for Storage.

func (*FaultyStorage) Close

func (s *FaultyStorage) Close(ctx context.Context) error

Close implements storage.Storage

func (*FaultyStorage) ConnectionInfo

func (s *FaultyStorage) ConnectionInfo() storage.ConnectionInfo

ConnectionInfo implements storage.Storage

func (*FaultyStorage) DeleteBlock

func (s *FaultyStorage) DeleteBlock(ctx context.Context, id string) error

DeleteBlock implements storage.Storage

func (*FaultyStorage) GetBlock

func (s *FaultyStorage) GetBlock(ctx context.Context, id string, offset, length int64) ([]byte, error)

GetBlock implements storage.Storage

func (*FaultyStorage) ListBlocks

func (s *FaultyStorage) ListBlocks(ctx context.Context, prefix string, callback func(storage.BlockMetadata) error) error

ListBlocks implements storage.Storage

func (*FaultyStorage) PutBlock

func (s *FaultyStorage) PutBlock(ctx context.Context, id string, data []byte) error

PutBlock implements storage.Storage

Jump to

Keyboard shortcuts

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