Documentation ¶
Overview ¶
Package shareddata provides data for tests and benchmarks.
Index ¶
Constants ¶
const (
Int32Interval = "[0, 2147483647]" // Int32Interval is [0, math.MaxInt32]
)
Variables ¶
var ArrayAndDocuments = &Values[string]{ name: "ArrayAndDocuments", data: map[string]any{ "document": bson.D{{"foo", int32(42)}}, "array-documents": bson.A{ bson.D{{"field", int32(42)}}, bson.D{{"field", int32(44)}}, bson.D{{"foo", int32(42)}}, }, "array-documents-two-fields": bson.A{ bson.D{ {"field", int32(42)}, {"foo", int32(44)}, }, bson.D{ {"field", int32(44)}, {"foo", int32(42)}, }, }, }, }
ArrayAndDocuments contain array and document values for tests. It is used for dot notation to find values from both document and array.
var ArrayDocuments = &Values[string]{ name: "ArrayDocuments", data: map[string]any{ "array-documents-nested": bson.A{ bson.D{{ "foo", bson.A{ bson.D{{"bar", "hello"}}, bson.D{{"bar", "world"}}, }, }}, }, "array-documents-nested-duplicate": bson.A{ bson.D{{ "foo", bson.A{ bson.D{{"bar", "hello"}}, bson.D{{"bar", "world"}}, }, }}, }, "array-two-documents": bson.A{ bson.D{{ "foo", bson.A{bson.D{{"bar", "hello"}}}, }}, bson.D{{ "foo", bson.A{bson.D{{"bar", "hello"}}}, }}, }, "array-three-documents": bson.A{ bson.D{{ "bar", bson.A{bson.D{{"a", "b"}}}, }}, bson.D{{ "foo", bson.A{bson.D{{"bar", "hello"}}}, }}, bson.D{{ "foo", bson.A{bson.D{{"bar", "hello"}}}, }}, }, }, }
ArrayDocuments contains array with documents with arrays: {"v": [{"foo": [{"bar": "hello"}]}, ...]}. This data set is helpful for dot notation tests: v.0.foo.0.bar.
var ArrayDoubles = &Values[string]{ name: "ArrayDoubles", data: map[string]any{ "array-double-desc": bson.A{float64(40), float64(15), float64(10)}, "array-double-duplicate": bson.A{float64(10), float64(10), float64(20)}, "array-double-big": bson.A{doubleBig}, "array-double-big-plus": bson.A{doubleBig + 1}, "array-double-prec-max": bson.A{doubleMaxPrec}, "array-double-prec-max-plus": bson.A{doubleMaxPrec + 1}, "array-double-empty": bson.A{}, }, }
ArrayDoubles contains an array with float64 values for tests.
var ArrayInt32s = &Values[string]{ name: "ArrayInt32s", data: map[string]any{ "array-int32-one": bson.A{int32(42)}, "array-int32-two": bson.A{int32(42), int32(42)}, "array-int32-three": bson.A{int32(42), int32(43), int32(42)}, "array-int32-empty": bson.A{}, "array-int32-six": bson.A{ int32(42), int32(43), int32(44), int32(45), int32(42), int32(43), }, }, }
ArrayInt32s contains an array with int32 values for tests.
var ArrayInt64s = &Values[string]{ name: "ArrayInt64s", data: map[string]any{ "array-long-big": bson.A{int64(doubleBig)}, "array-long-big-plus": bson.A{int64(doubleBig) + 1}, "array-long-prec-max": bson.A{int64(doubleMaxPrec)}, "array-long-prec-max-plus": bson.A{int64(doubleMaxPrec) + 1}, }, }
ArrayInt64s contains an array with int64 values for tests.
var ArrayRegexes = &Values[string]{ name: "ArrayRegexes", data: map[string]any{ "array-regex": bson.A{primitive.Regex{Pattern: "foo", Options: "i"}, primitive.Regex{Pattern: "foo", Options: "i"}}, }, }
ArrayRegexes contains an array with regex values for tests.
var ArrayStrings = &Values[string]{ name: "ArrayStrings", data: map[string]any{ "array-string-desc": bson.A{"c", "b", "a"}, "array-string-duplicate": bson.A{nil, "foo", "b", "b", nil}, "array-string-numbers": bson.A{"42", "0", "42.13"}, "array-string-empty": bson.A{}, "array-string-with-nil": bson.A{nil}, }, }
ArrayStrings contains an array with string values for tests.
var BenchmarkSettingsDocuments = newGeneratorBenchmarkProvider("SettingsDocuments", func(docs int) generatorFunc { var total int f := newFaker() return func() bson.D { if total >= docs { return nil } doc := make(bson.D, 100) doc[0] = bson.E{"_id", f.ObjectID()} for i := 1; i < len(doc); i++ { doc[i] = bson.E{ Key: f.FieldName(), Value: f.ScalarValue(), } } total++ return doc } })
BenchmarkSettingsDocuments provides large documents with 100 fields of various types.
It simulates a settings document like the one FastNetMon uses.
var BenchmarkSmallDocuments = newGeneratorBenchmarkProvider("SmallDocuments", func(docs int) generatorFunc { values := []any{ "foo", int32(42), "42", bson.D{{"foo", int32(42)}}, } l := len(values) var total int return func() bson.D { if total >= docs { return nil } doc := bson.D{ {"_id", int32(total)}, {"id", int32(total)}, {"v", values[total%l]}, } total++ return doc } })
BenchmarkSmallDocuments provides documents that look like:
{_id: int32(0), id: int32(0), v: "foo"} {_id: int32(1), id: int32(1), v: int32(42)} {_id: int32(2), id: int32(2), v: "42"} {_id: int32(3), id: int32(3), v: {"foo": int32(42)}} ...
`_id` is an int32 primary key that starts from 0. `id` has the same value as `_id`, but is not indexed by default. `v` has one of the four values shown above.
var Binaries = &Values[string]{ name: "Binaries", data: map[string]any{ "binary": primitive.Binary{Subtype: 0x80, Data: []byte{42, 0, 13}}, "binary-empty": primitive.Binary{Data: []byte{}}, "binary-null": nil, }, }
Binaries contains binary values for tests.
var Bools = &Values[string]{ name: "Bools", data: map[string]any{ "bool-false": false, "bool-true": true, "bool-null": nil, }, }
Bools contains bool values for tests.
var Composites = &Values[string]{ name: "Composites", data: map[string]any{ "document": bson.D{{"foo", int32(42)}}, "document-composite": bson.D{ {"foo", int32(42)}, {"42", "foo"}, {"array", bson.A{int32(42), "foo", nil}}, }, "document-composite-reverse": bson.D{ {"array", bson.A{int32(42), "foo", nil}}, {"42", "foo"}, {"foo", int32(42)}, }, "document-composite-numerical-field-name": bson.D{ {"foo", int32(42)}, {"42", "foo"}, {"array", bson.D{{"42", int32(42)}}}, }, "document-null": bson.D{{"foo", nil}}, "document-empty": bson.D{}, "array": bson.A{int32(42)}, "array-two": bson.A{42.13, "foo"}, "array-three": bson.A{int32(42), "foo", nil}, "array-three-reverse": bson.A{nil, "foo", int32(42)}, "array-empty": bson.A{}, "array-null": bson.A{nil}, "array-numbers-asc": bson.A{int32(42), int64(43), 45.5}, "array-strings-desc": bson.A{"c", "b", "a"}, "array-documents": bson.A{bson.D{{"field", int32(42)}}, bson.D{{"field", int32(44)}}}, "array-composite": bson.A{ 42.13, "foo", primitive.Binary{Subtype: 0x80, Data: []byte{42, 0, 13}}, primitive.ObjectID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11}, true, primitive.NewDateTimeFromTime(time.Date(2021, 11, 1, 10, 18, 42, 123000000, time.UTC)), nil, primitive.Regex{Pattern: "foo", Options: "i"}, int32(42), primitive.Timestamp{T: 42, I: 13}, int64(41), }, }, }
Composites contain composite values for tests.
This shared data set is not frozen yet, but please add to it only if it is really shared.
var DateTimes = &Values[string]{ name: "DateTimes", data: map[string]any{ "datetime": primitive.NewDateTimeFromTime(time.Date(2021, 11, 1, 10, 18, 42, 123000000, time.UTC)), "datetime-epoch": primitive.NewDateTimeFromTime(time.Unix(0, 0)), "datetime-year-min": primitive.NewDateTimeFromTime(time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC)), "datetime-year-max": primitive.NewDateTimeFromTime(time.Date(9999, 12, 31, 23, 59, 59, 999000000, time.UTC)), "datetime-null": nil, }, }
DateTimes contains datetime values for tests.
var DocumentsDeeplyNested = &Values[string]{ name: "DocumentsDeeplyNested", data: map[string]any{ "two": bson.D{{"a", bson.D{{"b", 12}}}}, "three": bson.D{{"a", bson.D{{"b", bson.D{{"c", 12}}}}}}, "four": bson.D{ {"a", bson.D{ {"b", bson.D{ {"c", bson.D{ {"d", 123}, }}, {"e", 13}, }}, {"f", 14}, }}, {"g", 15}, }, "array": bson.D{ {"a", bson.D{ {"b", bson.D{ {"c", bson.A{1, 2}}, {"e", 13}, }}, {"f", 14}, }}, {"g", 15}, }, }, }
DocumentsDeeplyNested contains documents nested in multiple levels for tests.
var DocumentsDocuments = &Values[primitive.ObjectID]{ name: "DocumentsDocuments", data: map[primitive.ObjectID]any{ {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}: bson.D{{"foo", int32(42)}}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}: bson.D{{"bar", bson.D{}}}, {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}: bson.D{{"_id", bson.A{int32(42), int32(42)}}}, {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}: bson.D{{"_id", bson.D{{"foo", "bar"}}}}, {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}: bson.D{{"_id", bson.D{{"_id", primitive.Regex{Pattern: "foo", Options: "i"}}}}}, }, }
DocumentsDocuments contains documents with documents for tests.
var DocumentsDoubles = &Values[string]{ name: "DocumentsDoubles", data: map[string]any{ "document-double": bson.D{{"v", 42.13}}, "document-double-whole": bson.D{{"v", 42.0}}, "document-double-zero": bson.D{{"v", 0.0}}, "document-double-max": bson.D{{"v", math.MaxFloat64}}, "document-double-smallest": bson.D{{"v", math.SmallestNonzeroFloat64}}, "document-double-big": bson.D{{"v", doubleBig}}, "document-double-empty": bson.D{}, "document-double-null": nil, }, }
DocumentsDoubles contains documents with double values for tests.
var DocumentsStrings = &Values[string]{ name: "DocumentsStrings", data: map[string]any{ "document-string": bson.D{{"v", "foo"}}, "document-string-double": bson.D{{"v", "42.13"}}, "document-string-whole": bson.D{{"v", "42"}}, "document-string-empty-str": bson.D{{"v", ""}}, "document-string-empty": bson.D{}, "document-string-nil": nil, }, }
DocumentsStrings contains documents with string values for tests.
var Doubles = &Values[string]{ name: "Doubles", data: map[string]any{ "double": 42.13, "double-whole": 42.0, "double-zero": 0.0, "double-smallest": math.SmallestNonzeroFloat64, "double-big": doubleBig, "double-big-plus": doubleBig + 1, "double-big-minus": doubleBig - 1, "double-prec-max": doubleMaxPrec, "double-prec-max-plus": doubleMaxPrec + 1, "double-prec-max-plus-two": doubleMaxPrec + 2, "double-prec-max-minus": doubleMaxPrec - 1, "double-neg-big": -doubleBig, "double-neg-big-plus": -doubleBig + 1, "double-neg-big-minus": -doubleBig - 1, "double-prec-min": -doubleMaxPrec, "double-prec-min-plus": -doubleMaxPrec + 1, "double-prec-min-minus": -doubleMaxPrec - 1, "double-prec-min-minus-two": -doubleMaxPrec - 2, "double-null": nil, "double-1": float64(math.MinInt64), "double-2": float64(-123456789), "double-3": float64(123456789), "double-4": float64(math.MaxInt64), "double-max-overflow": doubleMaxOverflow, "double-min-overflow": doubleMinOverflow, }, }
Doubles contains double values for tests.
var Int32s = &Values[string]{ name: "Int32s", data: map[string]any{ "int32": int32(42), "int32-zero": int32(0), "int32-max": int32(math.MaxInt32), "int32-min": int32(math.MinInt32), "int32-1": int32(4080), "int32-2": int32(1048560), "int32-3": int32(268435440), }, }
Int32s contains int32 values for tests.
var Int64s = &Values[string]{ name: "Int64s", data: map[string]any{ "int64": int64(42), "int64-zero": int64(0), "int64-max": int64(math.MaxInt64), "int64-min": int64(math.MinInt64), "int64-1": int64(1099511628000), "int64-2": int64(281474976700000), "int64-3": int64(72057594040000000), "int64-big": longBig, "int64-big-plus": longBig + 1, "int64-big-minus": longBig - 1, "int64-prec-max": int64(doubleMaxPrec), "int64-prec-max-plus": int64(doubleMaxPrec) + 1, "int64-prec-max-plus-two": int64(doubleMaxPrec) + 2, "int64-prec-max-minus": int64(doubleMaxPrec) - 1, "int64-neg-big": -longBig, "int64-neg-big-plus": -longBig + 1, "int64-neg-big-minus": -longBig - 1, "int64-prec-min": -int64(doubleMaxPrec), "int64-prec-min-plus": -int64(doubleMaxPrec) + 1, "int64-prec-min-minus": -int64(doubleMaxPrec) - 1, "int64-prec-min-minus-two": -int64(doubleMaxPrec) - 2, }, }
Int64s contains int64 values for tests.
var Mixed = &Values[string]{ name: "Mixed", data: map[string]any{ "null": nil, "unset": unset, "array-empty": bson.A{}, "array-null": bson.A{nil}, }, }
Mixed contains composite and scalar values for tests. It is used for sorting mixture of array and scalar documents.
Nulls contains null value for tests.
var ObjectIDKeys = &Values[primitive.ObjectID]{ name: "ObjectIDKeys", data: map[primitive.ObjectID]any{ {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11}: "objectid", primitive.NilObjectID: "objectid-empty", }, }
ObjectIDKeys contains documents with ObjectID keys for tests.
var ObjectIDs = &Values[string]{ name: "ObjectIDs", data: map[string]any{ "objectid": primitive.ObjectID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11}, "objectid-empty": primitive.NilObjectID, "objectid-null": nil, }, }
ObjectIDs contains ObjectID values for tests.
var OverflowVergeDoubles = &Values[string]{ name: "OverflowVergeDoubles", data: map[string]any{ "double-max": math.MaxFloat64, "double-7": doubleMaxVerge, }, }
OverflowVergeDoubles contains double values which would overflow on numeric update operation such as $mul. Upon such, target returns error and compat returns +INF or -INF. OverflowVergeDoubles may be excluded on such update tests and tested in diff tests https://github.com/FerretDB/dance.
var PostgresEdgeCases = &Values[string]{ name: "PostgresEdgeCases", data: map[string]any{ "document-notations": bson.D{ {"foo[0]", int32(42)}, {"*", int32(42)}, {"foo[*]", int32(42)}, {"@", int32(42)}, {"f,oo", int32(42)}, }, }, }
PostgresEdgeCases contains documents with keys and values that could be parsed in a wrong way on pg backend.
var Regexes = &Values[string]{ name: "Regexes", data: map[string]any{ "regex": primitive.Regex{Pattern: "foo", Options: "i"}, "regex-empty": primitive.Regex{}, "regex-null": nil, }, }
Regexes contains regex values for tests.
var Scalars = &Values[string]{ name: "Scalars", data: map[string]any{ "double": 42.13, "double-whole": 42.0, "double-zero": 0.0, "double-max": math.MaxFloat64, "double-smallest": math.SmallestNonzeroFloat64, "double-big": doubleBig, "double-1": float64(math.MinInt64), "double-2": float64(-123456789), "double-3": float64(123456789), "double-4": float64(math.MaxInt64), "double-5": doubleMaxVerge, "double-max-overflow": doubleMaxOverflow, "double-min-overflow": doubleMinOverflow, "string": "foo", "string-double": "42.13", "string-whole": "42", "string-empty": "", "binary": primitive.Binary{Subtype: 0x80, Data: []byte{42, 0, 13}}, "binary-empty": primitive.Binary{Data: []byte{}}, "objectid": primitive.ObjectID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11}, "objectid-empty": primitive.NilObjectID, "bool-false": false, "bool-true": true, "datetime": primitive.NewDateTimeFromTime(time.Date(2021, 11, 1, 10, 18, 42, 123000000, time.UTC)), "datetime-epoch": primitive.NewDateTimeFromTime(time.Unix(0, 0)), "datetime-year-min": primitive.NewDateTimeFromTime(time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC)), "datetime-year-max": primitive.NewDateTimeFromTime(time.Date(9999, 12, 31, 23, 59, 59, 999000000, time.UTC)), "null": nil, "regex": primitive.Regex{Pattern: "foo", Options: "i"}, "regex-empty": primitive.Regex{}, "int32": int32(42), "int32-zero": int32(0), "int32-max": int32(math.MaxInt32), "int32-min": int32(math.MinInt32), "int32-1": int32(4080), "int32-2": int32(1048560), "int32-3": int32(268435440), "timestamp": primitive.Timestamp{T: 42, I: 13}, "timestamp-i": primitive.Timestamp{I: 1}, "int64": int64(42), "int64-zero": int64(0), "int64-max": int64(math.MaxInt64), "int64-min": int64(math.MinInt64), "int64-big": longBig, "int64-double-big": doubleBig, "int64-1": int64(1099511628000), "int64-2": int64(281474976700000), "int64-3": int64(72057594040000000), "unset": unset, }, }
Scalars contain scalar values for tests.
This shared data set is frozen. If you need more values, add them in the test itself.
var SmallDoubles = &Values[string]{ name: "SmallDoubles", data: map[string]any{ "double": 42.13, "double-whole": 42.0, "double-1": 4080.1234, "double-2": 1048560.0099, "double-3": 268435440.2, }, }
SmallDoubles contains double values that does not go close to the maximum safe precision for tests.
var Strings = &Values[string]{ name: "Strings", data: map[string]any{ "string": "foo", "string-double": "42.13", "string-whole": "42", "string-empty": "", "string-duplicate": "foo", "string-null": nil, }, }
Strings contains string values for tests.
var Timestamps = &Values[string]{ name: "Timestamps", data: map[string]any{ "timestamp": primitive.Timestamp{T: 42, I: 13}, "timestamp-i": primitive.Timestamp{I: 1}, "timestamp-null": nil, }, }
Timestamps contains timestamp values for tests.
var Unsets = &Values[string]{ name: "Unsets", data: map[string]any{ "unset": unset, }, }
Unsets contains unset value for tests.
Functions ¶
Types ¶
type BenchmarkGenerator ¶
type BenchmarkGenerator interface { // Init sets the number of documents to generate. Init(docs int) BenchmarkProvider }
BenchmarkGenerator provides documents for benchmarks by generating them.
type BenchmarkProvider ¶
type BenchmarkProvider interface { // Name returns full benchmark provider name. Name() string // BaseName returns a part of the full name that does not include a number of documents and their hash. BaseName() string // NewIterator returns a new iterator for the same documents. NewIterator() iterator.Interface[struct{}, bson.D] }
BenchmarkProvider is implemented by shared data sets that provide documents for benchmarks.
func AllBenchmarkProviders ¶
func AllBenchmarkProviders() []BenchmarkProvider
AllBenchmarkProviders returns all benchmark providers in random order.
type Fields ¶
type Fields []field
Fields is a slice of ordered field name value pair. To avoid fields being inserted in different order between compat and target, use a slice instead of a map.
type Provider ¶
type Provider interface { // Name returns provider name. Name() string // Docs returns shared data documents. // All calls should return the same set of documents, but may do so in different order. Docs() []bson.D }
Provider is implemented by shared data sets that provide documents.
func NewTopLevelFieldsProvider ¶
func NewTopLevelFieldsProvider[id comparable](name string, backends []string, data map[id]Fields) Provider
NewTopLevelFieldsProvider creates a new TopLevelValues provider.
type Providers ¶
type Providers []Provider
Providers are array of providers.
func AllProviders ¶
func AllProviders() Providers
AllProviders returns all providers in random order.
type Values ¶
type Values[idType comparable] struct { // contains filtered or unexported fields }
Values stores shared data documents as {"_id": key, "v": value} documents.