Skip to content

Commit

Permalink
Merge branch 'main' into aggregation-group-id-operators-2964
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jul 26, 2023
2 parents 360c368 + 19e1cdb commit afe96e7
Show file tree
Hide file tree
Showing 36 changed files with 967 additions and 369 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jpg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.webp filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
7 changes: 7 additions & 0 deletions .github/PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ We also look at the flows' metrics to gather more information about the team's d
Estimation mistakes should be an exception, not a norm.
Try to estimate on the planning as best as you can.

## Daily progress

We want our work to be visible and transparent.
This way we can help each other and make sure that we are on the right track.
To uphold these principles, we agree to make results of our daily work available for others through various means such as
pull requests, code reviews, created issues, or any other relevant method.

## Pull requests

For FerretDB Inc. engineers and long-term contributors,
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ In most cases, they should be used instead of (deprecated) `bson.D.Map()`,
The bar for adding new helpers is very high.
Please check all existing ones.

If there's a need to use any large number to test corner cases,
we create constants for them with explanation what do they represent, and refer to them.
For example:

```go
const doubleMaxPrec = float64(1<<53 - 1) // 9007199254740991.0: largest double values that could be represented as integer exactly
```

#### Integration tests naming guidelines

1. Test names should include the name of the command being tested.
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,10 @@ tasks:
desc: "Format and lint documentation"
run: once
cmds:
- bin/checkdocs
- docker compose run --rm textlint --fix --config build/.textlintrc "**/*.md" ".github/**/*.md"
- docker compose run --rm prettier --write --parser markdown --no-semi --single-quote --trailing-comma none "**/*.md"
- docker compose run --rm markdownlint "build/.markdownlint.yml" "**/*.md"
- bin/checkdocs

docs-dev:
desc: "Start documentation development server"
Expand Down
47 changes: 47 additions & 0 deletions integration/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,53 @@ func TestDebugError(t *testing.T) {
})
}

func TestCheckingNestedDocuments(t *testing.T) {
t.Parallel()

for name, tc := range map[string]struct {
doc any
err error
}{
"1ok": {
doc: CreateNestedDocument(1),
},
"10ok": {
doc: CreateNestedDocument(10),
},
"100ok": {
doc: CreateNestedDocument(100),
},
"179ok": {
doc: CreateNestedDocument(179),
},
"180fail": {
doc: CreateNestedDocument(180),
err: fmt.Errorf("bson.Array.ReadFrom (document has exceeded the max supported nesting: 179."),
},
"180endedWithDocumentFail": {
doc: bson.D{{"v", CreateNestedDocument(179)}},
err: fmt.Errorf("bson.Document.ReadFrom (document has exceeded the max supported nesting: 179."),
},
"1000fail": {
doc: CreateNestedDocument(1000),
err: fmt.Errorf("bson.Document.ReadFrom (document has exceeded the max supported nesting: 179."),
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
ctx, collection := setup.Setup(t)
_, err := collection.InsertOne(ctx, tc.doc)
if tc.err != nil {
require.Error(t, tc.err)
return
}

require.NoError(t, err)
})
}
}

func TestPingCommand(t *testing.T) {
t.Parallel()

Expand Down
26 changes: 26 additions & 0 deletions integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,29 @@ func generateDocuments(startID, endID int32) (bson.A, []bson.D) {

return arr, docs
}

// CreateNestedDocument creates a mock BSON document that consists of nested arrays and documents.
// The nesting level is based on integer parameter.
func CreateNestedDocument(n int) bson.D {
return createNestedDocument(n, false).(bson.D)
}

// createNestedDocument creates the nested n times object that consists of
// documents and arrays. If the arr is true, the root value will be array.
//
// This function should be used only internally.
// To generate values for tests please use
// exported CreateNestedDocument function.
func createNestedDocument(n int, arr bool) any {
var child any

if n > 0 {
child = createNestedDocument(n-1, !arr)
}

if arr {
return bson.A{child}
}

return bson.D{{"v", child}}
}
44 changes: 44 additions & 0 deletions integration/nested_document_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integration

import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
)

func TestCreateNestedDocument(t *testing.T) {
t.Parallel()

t.Run("0", func(t *testing.T) {
expected := bson.D{{"v", nil}}
actual := CreateNestedDocument(0)
assert.Equal(t, expected, actual)
})

t.Run("1", func(t *testing.T) {
expected := bson.D{{"v", bson.A{nil}}}
actual := CreateNestedDocument(1)
assert.Equal(t, expected, actual)
})

t.Run("2", func(t *testing.T) {
expected := bson.D{{"v", bson.A{bson.D{{"v", nil}}}}}
actual := CreateNestedDocument(2)
assert.Equal(t, expected, actual)
})
}
Loading

0 comments on commit afe96e7

Please sign in to comment.