-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate scale
param for dbStats
and collStats
correctly
#2418
Merged
Merged
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
c828017
wip
rumyantseva a76b6d0
wip
rumyantseva e9db5a5
Merge branch 'main' into issue-1346-stats
06df4cb
wip
rumyantseva 092cb9d
Merge branch 'issue-1346-stats' of https://github.com/rumyantseva/Fer…
rumyantseva 0939552
wip
rumyantseva 17f3727
Merge branch 'main' into issue-1346-stats
rumyantseva a02f874
wip
rumyantseva 065fc0f
wip
rumyantseva 83a80e9
linting things
rumyantseva 5ab050d
wip
rumyantseva 324cb14
wip
rumyantseva 124eb09
wip
rumyantseva eabaaa0
Merge branch 'main' into issue-1346-stats
7abc624
wip
rumyantseva 2656559
Merge branch 'issue-1346-stats' of https://github.com/rumyantseva/Fer…
rumyantseva c0f4adc
wip
rumyantseva 9dfb2b1
Merge branch 'main' into issue-1346-stats
50738d5
diff
rumyantseva 91bf238
wip
rumyantseva dcc9efe
Merge branch 'main' into issue-1346-stats
a13133b
Merge branch 'main' into issue-1346-stats
mergify[bot] 69bafab
Merge branch 'main' into issue-1346-stats
mergify[bot] aeb71ef
wip
rumyantseva d70a4e6
Merge branch 'main' into issue-1346-stats
318cd6e
Merge branch 'main' into issue-1346-stats
AlekSi a5c8c9d
Merge branch 'main' into issue-1346-stats
56e1dc5
wip
rumyantseva 8a7adda
wip
rumyantseva f0b5a46
wip
rumyantseva c302ef8
wip
rumyantseva ff5708a
wip
rumyantseva 8c5e55c
wip
rumyantseva 0ac1cd5
Merge branch 'main' into issue-1346-stats
3abcf2e
Merge branch 'main' into issue-1346-stats
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// 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 ( | ||
"errors" | ||
"math" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
|
||
"github.com/FerretDB/FerretDB/integration/setup" | ||
"github.com/FerretDB/FerretDB/integration/shareddata" | ||
"github.com/FerretDB/FerretDB/internal/util/must" | ||
) | ||
|
||
func TestCommandsAdministrationCompatCollStatsWithScale(t *testing.T) { | ||
t.Parallel() | ||
|
||
s := setup.SetupCompatWithOpts(t, &setup.SetupCompatOpts{ | ||
Providers: []shareddata.Provider{shareddata.DocumentsDocuments}, | ||
AddNonExistentCollection: true, | ||
}) | ||
|
||
ctx, targetCollection, compatCollection := s.Ctx, s.TargetCollections[0], s.CompatCollections[0] | ||
|
||
for name, tc := range map[string]struct { //nolint:vet // for readability | ||
scale any | ||
resultType compatTestCaseResultType | ||
altMessage string | ||
}{ | ||
"scaleOne": {scale: int32(1)}, | ||
"scaleBig": {scale: int64(1000)}, | ||
"scaleMaxInt": {scale: math.MaxInt64}, | ||
"scaleZero": {scale: int32(0), resultType: emptyResult}, | ||
"scaleNegative": {scale: int32(-100), resultType: emptyResult}, | ||
"scaleFloat": {scale: 2.8}, | ||
"scaleFloatNegative": {scale: -2.8, resultType: emptyResult}, | ||
"scaleMinFloat": {scale: -math.MaxFloat64, resultType: emptyResult}, | ||
"scaleMaxFloat": {scale: math.MaxFloat64}, | ||
"scaleString": { | ||
scale: "1", | ||
resultType: emptyResult, | ||
altMessage: `BSON field 'collStats.scale' is the wrong type 'string', expected types '[long, int, decimal, double]'`, | ||
}, | ||
"scaleObject": { | ||
scale: bson.D{{"a", 1}}, | ||
resultType: emptyResult, | ||
altMessage: `BSON field 'collStats.scale' is the wrong type 'object', expected types '[long, int, decimal, double]'`, | ||
}, | ||
"scaleNull": {scale: nil}, | ||
} { | ||
name, tc := name, tc | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Helper() | ||
|
||
t.Parallel() | ||
|
||
var targetRes bson.D | ||
targetCommand := bson.D{{"collStats", targetCollection.Name()}, {"scale", tc.scale}} | ||
targetErr := targetCollection.Database().RunCommand(ctx, targetCommand).Decode(&targetRes) | ||
|
||
var compatRes bson.D | ||
compatCommand := bson.D{{"collStats", compatCollection.Name()}, {"scale", tc.scale}} | ||
compatErr := compatCollection.Database().RunCommand(ctx, compatCommand).Decode(&compatRes) | ||
|
||
if tc.resultType == emptyResult { | ||
require.Error(t, compatErr) | ||
|
||
targetErr = UnsetRaw(t, targetErr) | ||
compatErr = UnsetRaw(t, compatErr) | ||
|
||
if tc.altMessage != "" { | ||
var expectedErr mongo.CommandError | ||
require.True(t, errors.As(compatErr, &expectedErr)) | ||
AssertEqualAltError(t, expectedErr, tc.altMessage, targetErr) | ||
} else { | ||
assert.Equal(t, compatErr, targetErr) | ||
} | ||
|
||
return | ||
} | ||
|
||
require.NoError(t, compatErr) | ||
require.NoError(t, targetErr) | ||
|
||
targetDoc := ConvertDocument(t, targetRes) | ||
compatDoc := ConvertDocument(t, compatRes) | ||
|
||
targetFactor := must.NotFail(targetDoc.Get("scaleFactor")) | ||
compatFactor := must.NotFail(compatDoc.Get("scaleFactor")) | ||
|
||
assert.Equal(t, compatFactor, targetFactor) | ||
}) | ||
} | ||
} | ||
|
||
func TestCommandsAdministrationCompatDBStatsWithScale(t *testing.T) { | ||
t.Parallel() | ||
|
||
s := setup.SetupCompatWithOpts(t, &setup.SetupCompatOpts{ | ||
Providers: []shareddata.Provider{shareddata.DocumentsDocuments}, | ||
AddNonExistentCollection: true, | ||
}) | ||
|
||
ctx, targetCollection, compatCollection := s.Ctx, s.TargetCollections[0], s.CompatCollections[0] | ||
|
||
for name, tc := range map[string]struct { //nolint:vet // for readability | ||
scale any | ||
resultType compatTestCaseResultType | ||
altMessage string | ||
}{ | ||
"scaleOne": {scale: int32(1)}, | ||
"scaleBig": {scale: int64(1000)}, | ||
"scaleFloat": {scale: 2.8}, | ||
"scaleNull": {scale: nil}, | ||
} { | ||
name, tc := name, tc | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Helper() | ||
|
||
t.Parallel() | ||
|
||
var targetRes bson.D | ||
targetCommand := bson.D{{"dbStats", int32(1)}, {"scale", tc.scale}} | ||
targetErr := targetCollection.Database().RunCommand(ctx, targetCommand).Decode(&targetRes) | ||
|
||
var compatRes bson.D | ||
compatCommand := bson.D{{"dbStats", int32(1)}, {"scale", tc.scale}} | ||
compatErr := compatCollection.Database().RunCommand(ctx, compatCommand).Decode(&compatRes) | ||
|
||
if tc.resultType == emptyResult { | ||
require.Error(t, compatErr) | ||
|
||
targetErr = UnsetRaw(t, targetErr) | ||
compatErr = UnsetRaw(t, compatErr) | ||
|
||
if tc.altMessage != "" { | ||
var expectedErr mongo.CommandError | ||
require.True(t, errors.As(compatErr, &expectedErr)) | ||
AssertEqualAltError(t, expectedErr, tc.altMessage, targetErr) | ||
} else { | ||
assert.Equal(t, compatErr, targetErr) | ||
} | ||
|
||
return | ||
} | ||
|
||
require.NoError(t, compatErr) | ||
require.NoError(t, targetErr) | ||
|
||
targetDoc := ConvertDocument(t, targetRes) | ||
compatDoc := ConvertDocument(t, compatRes) | ||
|
||
targetFactor := must.NotFail(targetDoc.Get("scaleFactor")) | ||
compatFactor := must.NotFail(compatDoc.Get("scaleFactor")) | ||
|
||
assert.Equal(t, compatFactor, targetFactor) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both points were ignored.
Updated possible error results are also not documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlekSi could you please leave more specific feedback? What exactly needs to be documented here?
Sometimes when I leave comments (e.g. for structure fields) you say that they are obvious and not needed. What needs to be documented here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fields are not top-level declarations. Global variables are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I document what each error in this list means?
Or should I document each function/method where these errors could be returned?
Or both? Or something else?