var ( // ErrEntityMapOpen is returned when a slice entity is accessed while the EntityMap is open ErrEntityMapOpen = errors.New("slices cannot be accessed while EntityMap is open") )
EntityMap is used to store entities during tests. This type enforces uniqueness so no two entities can have the same ID, even if they are of different types. It also enforces referential integrity so construction of an entity that references another (e.g. a database entity references a client) will fail if the referenced entity does not exist. Accessors are available for the BSON entities.
type EntityMap struct {
// contains filtered or unexported fields
}
func (em *EntityMap) BSONArray(id string) ([]bson.Raw, error)
BSONArray returns the BSON document array associated with id. This should only be accessed after the test is finished running
func (em *EntityMap) BSONValue(id string) (bson.RawValue, error)
BSONValue returns the bson.RawValue associated with id
func (em *EntityMap) EventList(id string) ([]bson.Raw, error)
EventList returns the array of event documents associated with id. This should only be accessed after the test is finished running
func (em *EntityMap) Iterations(id string) (int32, error)
Iterations returns the number of iterations associated with id
func (em *EntityMap) Successes(id string) (int32, error)
Successes returns the number of successes associated with id
Logger is the Sink used to captured log messages for logger verification in the unified spec tests.
type Logger struct {
// contains filtered or unexported fields
}
func (log *Logger) Error(err error, msg string, args ...interface{})
Error implements the logger.Sink interface's "Error" method for printing log errors. In this case, if an error occurs we will simply treat it as informational.
func (log *Logger) Info(level int, msg string, args ...interface{})
Info implements the logger.Sink interface's "Info" method for printing log messages.
LoggerSkipper is passed to TestCase.Run to allow it to perform logging and skipping operations
type LoggerSkipper interface { Log(args ...interface{}) Logf(format string, args ...interface{}) Skip(args ...interface{}) Skipf(format string, args ...interface{}) }
Options is the type used to configure tests
type Options struct { // Specifies if killAllSessions should be run after the test completes. // Defaults to true RunKillAllSessions *bool }
func MergeOptions(opts ...*Options) *Options
MergeOptions combines the given *Options into a single *Options in a last one wins fashion.
Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.
func NewOptions() *Options
NewOptions creates an empty options interface
func (op *Options) SetRunKillAllSessions(killAllSessions bool) *Options
SetRunKillAllSessions sets the value for RunKillAllSessions
ReadPreference is a representation of BSON readPreference objects in tests.
type ReadPreference struct { Mode string `bson:"mode"` TagSets []map[string]string `bson:"tagSets"` MaxStalenessSeconds *int64 `bson:"maxStalenessSeconds"` Hedge bson.M `bson:"hedge"` }
func (rp *ReadPreference) ToReadPrefOption() (*readpref.ReadPref, error)
ToReadPrefOption converts a ReadPreference into a readpref.ReadPref object and will error if the original ReadPreference is malformed.
TestCase holds and runs a unified spec test case
type TestCase struct { Description string `bson:"description"` RunOnRequirements []mtest.RunOnBlock `bson:"runOnRequirements"` SkipReason *string `bson:"skipReason"` Operations []*operation `bson:"operations"` ExpectedEvents []*expectedEvents `bson:"expectEvents"` ExpectLogMessages []*clientLogMessages `bson:"expectLogMessages"` Outcome []*collectionData `bson:"outcome"` // contains filtered or unexported fields }
func ParseTestFile(t *testing.T, testJSON []byte, expectValidFail bool, opts ...*Options) ([]mtest.RunOnBlock, []*TestCase)
ParseTestFile create an array of TestCases from the testJSON json blob
func (tc *TestCase) EndLoop()
EndLoop will cause the runner to stop a loop operation if one is included in the test. If the test has finished running, this will panic
func (tc *TestCase) GetEntities() *EntityMap
GetEntities returns a pointer to the EntityMap for the TestCase. This should not be called until after the test is run
func (tc *TestCase) Run(ls LoggerSkipper) error
Run runs the TestCase and returns an error if it fails
TestFile holds the contents of a unified spec test file
type TestFile struct { Description string `bson:"description"` SchemaVersion string `bson:"schemaVersion"` RunOnRequirements []mtest.RunOnBlock `bson:"runOnRequirements"` CreateEntities []map[string]*entityOptions `bson:"createEntities"` InitialData []*collectionData `bson:"initialData"` TestCases []*TestCase `bson:"tests"` }