drivertest

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package drivertest provides a conformance test for implementations of driver.

Index

Constants

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 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 RunConformanceTests

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

RunConformanceTests runs conformance tests for provider 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
	// BeforeDo will be passed directly to ActionList.BeforeDo as part of running
	// the test actions.
	BeforeDo(as func(interface{}) bool) error
	// BeforeQuery will be passed directly to Query.BeforeQuery as part of doing
	// the test query.
	BeforeQuery(as func(interface{}) bool) error
	// QueryCheck will be called after calling Query. It should call it.As and
	// verify the results.
	QueryCheck(it *docstore.DocumentIterator) 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 provider, and that provider's own "native" codec.

type Harness

type Harness interface {
	// MakeCollection makes a driver.Collection for testing.
	// The collection should have a single primary key field of type string named
	// drivertest.KeyField.
	MakeCollection(context.Context) (driver.Collection, error)

	// MakeTwoKeyCollection makes a driver.Collection for testing.
	// The collection 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.
	MakeTwoKeyCollection(ctx context.Context) (driver.Collection, error)

	// 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 any complex type
	Complex
	// 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