drivertest

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package drivertest provides a conformance test for implementations of driver.

Index

Constants

View Source
const AlternateRevisionField = "Etag"

AlternateRevisionField is used for testing the option to provide a different name for the revision field.

View Source
const KeyField = "name"

KeyField is the primary key field for the main test collection.

Variables

This section is empty.

Functions

func HighScoreKey

func HighScoreKey(doc docstore.Document) interface{}

HighScoreKey constructs a single primary key from a HighScore struct or a map with the same fields by concatenating the Game and Player fields.

func MakeUniqueStringDeterministicForTesting

func MakeUniqueStringDeterministicForTesting(seed int64)

MakeUniqueStringDeterministicForTesting uses a specified seed value to produce the same sequence of values in driver.UniqueString for testing.

Call when running tests that will be replayed.

func MustDocument

func MustDocument(doc interface{}) driver.Document

MustDocument is like driver.NewDocument, but panics on error.

func RunBenchmarks

func RunBenchmarks(b *testing.B, coll *docstore.Collection)

RunBenchmarks runs benchmarks for docstore drivers.

func RunConformanceTests

func RunConformanceTests(t *testing.T, newHarness HarnessMaker, ct CodecTester, asTests []AsTest)

RunConformanceTests runs conformance tests for driver implementations of docstore.

Types

type AsTest

type AsTest interface {
	// Name should return a descriptive name for the test.
	Name() string
	// CollectionCheck will be called to allow verification of Collection.As.
	CollectionCheck(coll *docstore.Collection) error
	// QueryCheck will be called after calling Query. It should call it.As and
	// verify the results.
	QueryCheck(it *docstore.DocumentIterator) error
	// ErrorCheck is called to allow verification of Collection.ErrorAs.
	ErrorCheck(c *docstore.Collection, err error) error
}

AsTest represents a test of As functionality.

type CodecTester

type CodecTester interface {
	UnsupportedTypes() []UnsupportedType
	NativeEncode(interface{}) (interface{}, error)
	NativeDecode(value, dest interface{}) error
	DocstoreEncode(interface{}) (interface{}, error)
	DocstoreDecode(value, dest interface{}) error
}

CodecTester describes functions that encode and decode values using both the docstore codec for a driver, and that driver's own "native" codec.

type CollectionKind

type CollectionKind int

CollectionKind describes the kind of testing collection to create.

const (
	// A collection with a single primary key field of type string named
	// drivertest.KeyField.
	SingleKey CollectionKind = iota

	// A collection that will consist entirely of HighScore structs (see below),
	// whose two primary key fields are "Game" and "Player", both strings. Use
	// drivertest.HighScoreKey as the key function.
	TwoKey

	// The collection should behave like a SingleKey collection, except
	// that the revision field should be drivertest.AlternateRevisionField.
	AltRev

	// The collection's documents will not have a revision field.
	NoRev
)

type Harness

type Harness interface {
	// MakeCollection makes a driver.Collection for testing.
	MakeCollection(context.Context, CollectionKind) (driver.Collection, error)

	// BeforeDoTypes should return a list of values whose types are valid for the as
	// function given to BeforeDo. For example, if the driver converts Get actions
	// to *GetRequests and write actions to *WriteRequests, then BeforeDoTypes should
	// return []interface{}{&GetRequest{}, &WriteRequest{}}.
	// TODO(jba): consider splitting these by action kind.
	BeforeDoTypes() []interface{}

	// BeforeQueryTypes should return a list of values whose types are valid for the as
	// function given to BeforeQuery.
	BeforeQueryTypes() []interface{}

	// RevisionsEqual reports whether two revisions are equal.
	RevisionsEqual(rev1, rev2 interface{}) bool

	// Close closes resources used by the harness.
	Close()
}

Harness descibes the functionality test harnesses must provide to run conformance tests.

type HarnessMaker

type HarnessMaker func(ctx context.Context, t *testing.T) (Harness, error)

HarnessMaker describes functions that construct a harness for running tests. It is called exactly once per test; Harness.Close() will be called when the test is complete.

type HighScore

type HighScore struct {
	Game             string
	Player           string
	Score            int
	Time             time.Time
	DocstoreRevision interface{}
}

A HighScore records one user's high score in a particular game. The primary key fields are Game and Player.

func (*HighScore) String

func (h *HighScore) String() string

type UnsupportedType

type UnsupportedType int

UnsupportedType is an enum for types not supported by native codecs. We chose to describe this negatively (types that aren't supported rather than types that are) to make the more inclusive cases easier to write. A driver can return nil for CodecTester.UnsupportedTypes, then add values from this enum one by one until all tests pass.

const (
	// Native codec doesn't support any unsigned integer type
	Uint UnsupportedType = iota
	// Native codec doesn't support arrays
	Arrays
	// Native codec doesn't support full time precision
	NanosecondTimes
	// Native codec doesn't support [][]byte
	BinarySet
)

These are known unsupported types by one or more driver. Each of them corresponses to an unsupported type specific test which if the driver actually supports.

Jump to

Keyboard shortcuts

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