Skip to content
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

Implement MsgCount for Tigris #928

Merged
merged 22 commits into from
Jul 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tigris MsgCounta and simple smoke tests
  • Loading branch information
Elena Grahovac committed Jul 21, 2022
commit ca7002ad596aa83869a4c9c163be0b326b495aa2
53 changes: 53 additions & 0 deletions integration/tigris/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package tigris

import (
"math"
"testing"

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

Expand All @@ -34,3 +36,54 @@ func TestSmoke(t *testing.T) {
require.NoError(t, err)
integration.AssertEqualDocuments(t, bson.D{{"_id", "fixed_double"}, {"double_value", 42.13}}, doc)
}

// TestSmokeMsgCount implements simple smoke tests for MsgCount.
// TODO Implement proper testing: https://github.com/FerretDB/FerretDB/issues/931.
func TestSmokeMsgCount(t *testing.T) {
t.Parallel()

// As Tigris require different fields for different types,
// for this smoke test we only use the fixed scalars.
ctx, collection := setup.Setup(t, shareddata.FixedScalars)

for name, tc := range map[string]struct {
command any
response int32
}{
"CountAllFixedScalars": {
command: bson.D{{"count", collection.Name()}},
response: 6,
},
"CountExactlyOneDocument": {
command: bson.D{
{"count", collection.Name()},
{"query", bson.D{{"double_value", math.MaxFloat64}}},
},
response: 1,
},
"CountNonExistingCollection": {
command: bson.D{
{"count", "doesnotexist"},
{"query", bson.D{{"v", true}}},
},
response: 0,
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()

var actual bson.D
err := collection.Database().RunCommand(ctx, tc.command).Decode(&actual)
require.NoError(t, err)

m := actual.Map()

assert.Equal(t, float64(1), m["ok"])

keys := integration.CollectKeys(t, actual)
assert.Contains(t, keys, "n")
assert.Equal(t, tc.response, m["n"])
})
}
}