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

Cleanup SQLite tests #3246

Merged
merged 18 commits into from
Aug 25, 2023
620 changes: 158 additions & 462 deletions integration/aggregate_documents_compat_test.go

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions integration/aggregate_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ func TestAggregateUnsetErrors(t *testing.T) {
}
}

func TestAggregateSortErrors(t *testing.T) {
t.Parallel()
func TestAggregateSortErrors(tt *testing.T) {
tt.Parallel()

for name, tc := range map[string]struct { //nolint:vet // used for test only
pipeline bson.A // required, aggregation pipeline stages
Expand All @@ -894,12 +894,14 @@ func TestAggregateSortErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down
21 changes: 12 additions & 9 deletions integration/aggregate_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ import (
"github.com/FerretDB/FerretDB/integration/shareddata"
)

func TestAggregateMatchExprErrors(t *testing.T) {
t.Parallel()
func TestAggregateMatchExprErrors(tt *testing.T) {
tt.Parallel()

ctx, collection := setup.Setup(t, shareddata.Composites)
ctx, collection := setup.Setup(tt, shareddata.Composites)

for name, tc := range map[string]struct { //nolint:vet // used for test only
pipeline bson.A // required, aggregation pipeline stages

err *mongo.CommandError // required
altMessage string // optional, alternative error message
skip string // optional, skip test with a specified reason
err *mongo.CommandError // required
altMessage string // optional, alternative error message
skip string // optional, skip test with a specified reason
failsForSQLite string // optional, if set, the case is expected to fail for SQLite due to given issue}
}{
"TooManyFields": {
pipeline: bson.A{
Expand Down Expand Up @@ -173,12 +174,14 @@ func TestAggregateMatchExprErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down
25 changes: 8 additions & 17 deletions integration/aggregate_variables_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ func TestAggregateVariablesCompatRoot(t *testing.T) {
pipeline: bson.A{
bson.D{{"$addFields", bson.D{{"field", "$$ROOT"}}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1413",
skip: "https://github.com/FerretDB/FerretDB/issues/1413",
},
"GroupID": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", 1}}}},
bson.D{{"$group", bson.D{{"_id", "$$ROOT"}}}},
bson.D{{"$sort", bson.D{{"_id", 1}}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
},
"GroupIDTwice": {
pipeline: bson.A{
Expand All @@ -51,8 +49,7 @@ func TestAggregateVariablesCompatRoot(t *testing.T) {
bson.D{{"$group", bson.D{{"_id", "$$ROOT"}}}},
bson.D{{"$sort", bson.D{{"_id", 1}}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
},
"GroupIDExpression": {
pipeline: bson.A{
Expand All @@ -62,8 +59,7 @@ func TestAggregateVariablesCompatRoot(t *testing.T) {
}}},
bson.D{{"$sort", bson.D{{"_id", 1}}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
},
"GroupSumAccumulator": {
pipeline: bson.A{
Expand All @@ -74,39 +70,34 @@ func TestAggregateVariablesCompatRoot(t *testing.T) {
}}},
bson.D{{"$sort", bson.D{{"_id", -1}}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
},
"ProjectSumOperator": {
pipeline: bson.A{
bson.D{{"$project", bson.D{
{"sum", bson.D{{"$sum", "$$ROOT"}}},
}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
},
"ProjectTypeOperator": {
pipeline: bson.A{
bson.D{{"$project", bson.D{
{"type", bson.D{{"$type", "$$ROOT"}}},
}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
skip: "https://github.com/FerretDB/FerretDB/issues/1992",
},
"Set": {
pipeline: bson.A{
bson.D{{"$set", bson.D{{"field", "$$ROOT"}}}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
skip: "https://github.com/FerretDB/FerretDB/issues/1413",
skip: "https://github.com/FerretDB/FerretDB/issues/1413",
},
"Unwind": {
pipeline: bson.A{
bson.D{{"$unwind", "$$ROOT"}},
},
failsForSQLite: "https://github.com/FerretDB/FerretDB/issues/3148",
resultType: emptyResult,
resultType: emptyResult,
},
}

Expand Down
2 changes: 1 addition & 1 deletion integration/findandmodify_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func TestFindAndModifyCompatUpsert(t *testing.T) {
{"new", true},
},
},
"UpsertNoSuchReplaceDocument": {
"UpsertNoReplaceDocument": {
command: bson.D{
{"query", bson.D{{"_id", "no-such-doc"}}},
{"update", bson.D{{"v", 43.13}}},
Expand Down
6 changes: 2 additions & 4 deletions integration/findandmodify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,8 @@ func TestFindAndModifyCommandUpsert(t *testing.T) {
}
}

func TestFindAndModifyCommentMethod(tt *testing.T) {
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3049")
func TestFindAndModifyCommentMethod(t *testing.T) {
t.Parallel()

ctx, collection := setup.Setup(t, shareddata.Scalars)

Expand Down
3 changes: 1 addition & 2 deletions integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package integration

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -294,7 +293,7 @@ func AssertEqualAltCommandError(t testtb.TB, expected mongo.CommandError, altMes

// AssertEqualAltWriteError asserts that the expected MongoDB error is the same as the actual;
// the alternative error message may be provided if FerretDB is unable to produce exactly the same text as MongoDB.
func AssertEqualAltWriteError(t *testing.T, expected mongo.WriteError, altMessage string, actual error) bool {
func AssertEqualAltWriteError(t testtb.TB, expected mongo.WriteError, altMessage string, actual error) bool {
t.Helper()

we, ok := actual.(mongo.WriteException)
Expand Down
48 changes: 28 additions & 20 deletions integration/indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/FerretDB/FerretDB/integration/shareddata"
)

func TestDropIndexesCommandErrors(t *testing.T) {
t.Parallel()
func TestDropIndexesCommandErrors(tt *testing.T) {
tt.Parallel()

for name, tc := range map[string]struct { //nolint:vet // for readability
toCreate []mongo.IndexModel // optional, if set, create the given indexes before drop is called
Expand Down Expand Up @@ -132,12 +132,14 @@ func TestDropIndexesCommandErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3183")

if tc.command != nil {
require.Nil(t, tc.toDrop, "toDrop must be nil when using command")
Expand Down Expand Up @@ -175,8 +177,8 @@ func TestDropIndexesCommandErrors(t *testing.T) {
}
}

func TestCreateIndexesCommandInvalidSpec(t *testing.T) {
t.Parallel()
func TestCreateIndexesCommandInvalidSpec(tt *testing.T) {
tt.Parallel()

for name, tc := range map[string]struct {
indexes any // optional
Expand Down Expand Up @@ -369,12 +371,14 @@ func TestCreateIndexesCommandInvalidSpec(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3183")

if tc.missingIndexes {
require.Nil(t, tc.indexes, "indexes must be nil if missingIndexes is true")
Expand Down Expand Up @@ -409,8 +413,8 @@ func TestCreateIndexesCommandInvalidSpec(t *testing.T) {
}
}

func TestCreateIndexesCommandInvalidCollection(t *testing.T) {
t.Parallel()
func TestCreateIndexesCommandInvalidCollection(tt *testing.T) {
tt.Parallel()

for name, tc := range map[string]struct {
collectionName any
Expand Down Expand Up @@ -465,12 +469,14 @@ func TestCreateIndexesCommandInvalidCollection(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3183")

provider := shareddata.ArrayDocuments // one provider is enough to check for errors
ctx, collection := setup.Setup(t, provider)
Expand All @@ -489,8 +495,8 @@ func TestCreateIndexesCommandInvalidCollection(t *testing.T) {
}
}

func TestDropIndexesCommandInvalidCollection(t *testing.T) {
t.Parallel()
func TestDropIndexesCommandInvalidCollection(tt *testing.T) {
tt.Parallel()

for name, tc := range map[string]struct {
collectionName any
Expand Down Expand Up @@ -539,12 +545,14 @@ func TestDropIndexesCommandInvalidCollection(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3183")

provider := shareddata.ArrayDocuments // one provider is enough to check for errors
ctx, collection := setup.Setup(t, provider)
Expand Down
4 changes: 2 additions & 2 deletions integration/insert_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func TestInsertCommandErrors(tt *testing.T) {
assert.Nil(t, res)

if tc.cerr != nil {
AssertEqualAltCommandError(tt, *tc.cerr, tc.altMessage, err)
AssertEqualAltCommandError(t, *tc.cerr, tc.altMessage, err)
return
}

if tc.werr != nil {
AssertEqualAltWriteError(tt, *tc.werr, tc.altMessage, err)
AssertEqualAltWriteError(t, *tc.werr, tc.altMessage, err)
return
}

Expand Down
Loading