Documentation ¶
Overview ¶
Package drivertest provides a conformance test for implementations of driver.
Index ¶
- Constants
- func HighScoreKey(doc docstore.Document) interface{}
- func MakeUniqueStringDeterministicForTesting(seed int64)
- func MustDocument(doc interface{}) driver.Document
- func RunBenchmarks(b *testing.B, coll *docstore.Collection)
- func RunConformanceTests(t *testing.T, newHarness HarnessMaker, ct CodecTester, asTests []AsTest)
- type AsTest
- type ByteArray
- type CodecTester
- type CollectionKind
- type Harness
- type HarnessMaker
- type HighScore
- type UnsupportedType
Constants ¶
const AlternateRevisionField = "Etag"
AlternateRevisionField is used for testing the option to provide a different name for the revision field.
const KeyField = "name"
KeyField is the primary key field for the main test collection.
Variables ¶
This section is empty.
Functions ¶
func HighScoreKey ¶
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 ¶
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 ¶
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.
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.