Skip to content

Commit

Permalink
Merge branch 'main' into setup-user-env-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
chilagrow committed Mar 5, 2024
2 parents 4c4add2 + dc757b9 commit 8d5ca45
Show file tree
Hide file tree
Showing 15 changed files with 502 additions and 111 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -13,6 +13,7 @@ require (
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgx-zap v0.0.0-20221202020421-94b1cb2f889f
github.com/jackc/pgx/v5 v5.5.3
github.com/neilotoole/slogt v1.1.0
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -74,6 +74,8 @@ github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwp
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/neilotoole/slogt v1.1.0 h1:c7qE92sq+V0yvCuaxph+RQ2jOKL61c4hqS1Bv9W7FZE=
github.com/neilotoole/slogt v1.1.0/go.mod h1:RCrGXkPc/hYybNulqQrMHRtvlQ7F6NktNVLuLwk6V+w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
Expand Down
2 changes: 1 addition & 1 deletion integration/go.mod
Expand Up @@ -7,7 +7,6 @@ replace github.com/FerretDB/FerretDB => ../
require (
github.com/AlekSi/pointer v1.2.0
github.com/FerretDB/FerretDB v0.0.0-00010101000000-000000000000
github.com/jaswdr/faker v1.19.1
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.8.4
go.mongodb.org/mongo-driver v1.14.0
Expand Down Expand Up @@ -44,6 +43,7 @@ require (
github.com/klauspost/compress v1.13.6 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/neilotoole/slogt v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integration/go.sum
Expand Up @@ -52,8 +52,6 @@ github.com/jackc/pgx/v5 v5.5.3 h1:Ces6/M3wbDXYpM8JyyPD57ivTtJACFZJd885pdIaV2s=
github.com/jackc/pgx/v5 v5.5.3/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jaswdr/faker v1.19.1 h1:xBoz8/O6r0QAR8eEvKJZMdofxiRH+F0M/7MU9eNKhsM=
github.com/jaswdr/faker v1.19.1/go.mod h1:x7ZlyB1AZqwqKZgyQlnqEG8FDptmHlncA5u2zY/yi6w=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
Expand All @@ -68,6 +66,8 @@ github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwp
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/neilotoole/slogt v1.1.0 h1:c7qE92sq+V0yvCuaxph+RQ2jOKL61c4hqS1Bv9W7FZE=
github.com/neilotoole/slogt v1.1.0/go.mod h1:RCrGXkPc/hYybNulqQrMHRtvlQ7F6NktNVLuLwk6V+w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
Expand Down
224 changes: 208 additions & 16 deletions integration/shareddata/faker.go
Expand Up @@ -15,22 +15,213 @@
package shareddata

import (
"fmt"
"math"
"math/rand"
"strconv"
"time"

fakerlib "github.com/jaswdr/faker"
"go.mongodb.org/mongo-driver/bson/primitive"

"github.com/FerretDB/FerretDB/internal/util/must"
)

// faker generates stable fake data for tests.
// words is a list of words used for generating random data.
var words = [...]string{
"access",
"additional",
"against",
"aggregate",
"all",
"allow",
"allowed",
"allows",
"along",
"an",
"and",
"any",
"anyone",
"apply",
"are",
"as",
"at",
"attached",
"author",
"away",
"be",
"being",
"build",
"built",
"business",
"by",
"carry",
"charge",
"code",
"compiled",
"comply",
"component",
"conjunction",
"containing",
"cost",
"criteria",
"deliberately",
"depend",
"derived",
"different",
"discriminate",
"discrimination",
"distributed",
"distribution",
"doesn",
"downloading",
"endeavor",
"example",
"execution",
"explicitly",
"extracted",
"fee",
"field",
"fields",
"files”",
"following",
"for",
"form",
"forms",
"free",
"from",
"genetic",
"giving",
"granted",
"group",
"groups",
"have",
"if",
"in",
"include",
"individual",
"insist",
"integrity",
"interface",
"intermediate",
"internet",
"introduction",
"is",
"it",
"just",
"license",
"licensed",
"making",
"may",
"mean",
"means",
"medium",
"modifications",
"modified",
"modify",
"modifying",
"more",
"must",
"name",
"need",
"no",
"not",
"number",
"obfuscated",
"obtaining",
"of",
"on",
"only",
"open",
"or",
"original",
"other",
"output",
"part",
"particular",
"parties",
"party",
"patch",
"permit",
"person",
"persons",
"place",
"predicated",
"preferably",
"preferred",
"preprocessor",
"product",
"program",
"programmer",
"programs",
"provision",
"purpose",
"reasonable",
"redistributed",
"redistribution",
"reproduction",
"require",
"research",
"restrict",
"restrictions",
"rights",
"royalty",
"sale",
"same",
"selling",
"several",
"shall",
"should",
"software",
"some",
"source",
"source-code",
"sources",
"specific",
"style",
"such",
"technology",
"technology-neutral",
"terms",
"than",
"that",
"the",
"them",
"there",
"those",
"time",
"to",
"translator",
"under",
"use",
"used",
"version",
"via",
"well",
"well-publicized",
"where",
"which",
"whom",
"with",
"within",
"without",
"works",
"would",
}

// wordsB is words as []byte.
var wordsB [len(words)][]byte

// init initializes wordsB.
func init() {
for i, w := range words {
wordsB[i] = []byte(w)
}
}

// faker generates stable fake data for tests and benchmarks.
//
// It is not thread-safe.
type faker struct {
r *rand.Rand
f fakerlib.Faker
}

// newFaker creates a new faker.
Expand All @@ -39,16 +230,12 @@ func newFaker() *faker {

return &faker{
r: rand.New(src),
f: fakerlib.NewWithSeed(src),
}
}

// FieldName generates a random document field name.
func (f *faker) FieldName() string {
// See https://github.com/jaswdr/faker/issues/142.

// somewhat surprisingly, generating "better" field names generates duplicates too often
return fmt.Sprintf("field_%d", f.r.Int())
return "field_" + strconv.Itoa(f.r.Int())
}

// ObjectID generates a random non-zero ObjectID.
Expand All @@ -66,27 +253,32 @@ func (f *faker) ScalarValue() any {
for {
switch f.r.Intn(0x13) + 1 {
case 0x01: // Double
return f.r.Float64()
for {
f := math.Float64frombits(f.r.Uint64())
if !math.IsNaN(f) { // to simplify comparisons
return f
}
}
case 0x02: // String
return f.f.Lorem().Words(10)
return words[f.r.Intn(len(words))]
case 0x05: // Binary
return primitive.Binary{Subtype: 0x00, Data: f.f.Lorem().Bytes(1000)}
return primitive.Binary{Subtype: 0x00, Data: wordsB[f.r.Intn(len(wordsB))]}
case 0x07: // ObjectID
return f.ObjectID()
case 0x08: // Bool
return f.f.Bool()
return f.r.Intn(2) == 1
case 0x09: // DateTime
return f.f.Time().Time(time.Date(2021, 11, 1, 10, 18, 42, 123000000, time.UTC))
return time.UnixMilli(int64(int32(f.r.Uint32())) * 1000) // 1901-2038 to make JSON encoder happy
case 0x0a: // Null
return nil
case 0x0b: // Regex
// not yet
case 0x10: // Int32
return f.f.Int32()
return int32(f.r.Uint32())
case 0x11: // Timestamp
// not yet
case 0x12: // Int64
return f.f.Int64()
return int64(f.r.Uint64())
case 0x13: // Decimal
// TODO https://github.com/FerretDB/FerretDB/issues/66
default:
Expand Down

0 comments on commit 8d5ca45

Please sign in to comment.