gocloud.dev: gocloud.dev/docstore/drivertest Index | Files

package drivertest

import "gocloud.dev/docstore/drivertest"

Package drivertest provides a conformance test for implementations of driver.

Index

Package Files

driverbenchmark.go drivertest.go util.go

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.

func HighScoreKey Uses

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 Uses

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 Uses

func MustDocument(doc interface{}) driver.Document

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

func RunBenchmarks Uses

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

RunBenchmarks runs benchmarks for docstore drivers.

func RunConformanceTests Uses

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

RunConformanceTests runs conformance tests for driver implementations of docstore.

type AsTest Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (h *HighScore) String() string

type UnsupportedType Uses

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.

Package drivertest imports 19 packages (graph). Updated 2019-08-14. Refresh now. Tools for package owners.