Skip to content

Commit

Permalink
Merge branch 'main' into issue-774-msgdbstats
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Aug 17, 2022
2 parents 475d30d + 1533c4b commit 2d4c31c
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 111 deletions.
13 changes: 6 additions & 7 deletions integration/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/FerretDB/FerretDB/integration/setup"
"github.com/FerretDB/FerretDB/integration/shareddata"
"github.com/FerretDB/FerretDB/internal/util/testutil"
)

func TestMostCommandsAreCaseSensitive(t *testing.T) {
Expand Down Expand Up @@ -385,17 +384,17 @@ func TestDatabaseName(t *testing.T) {
Message: fmt.Sprintf(
"Invalid namespace specified '%s.%s'",
dbName64,
"TestDatabaseName_Err_TooLongForBothDBs",
"TestDatabaseName_Err",
),
},
alt: fmt.Sprintf("Invalid namespace: %s.%s", dbName64, "TestDatabaseName_Err_TooLongForBothDBs"),
alt: fmt.Sprintf("Invalid namespace: %s.%s", dbName64, "TestDatabaseName_Err"),
},
"WithADollarSign": {
db: "name_with_a-$",
err: &mongo.CommandError{
Name: "InvalidNamespace",
Code: 73,
Message: `Invalid namespace: name_with_a-$.TestDatabaseName_Err_WithADollarSign`,
Message: `Invalid namespace: name_with_a-$.TestDatabaseName_Err`,
},
},
}
Expand All @@ -404,7 +403,7 @@ func TestDatabaseName(t *testing.T) {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
// there is no explicit command to create database, so create collection instead
err := collection.Database().Client().Database(tc.db).CreateCollection(ctx, testutil.CollectionName(t))
err := collection.Database().Client().Database(tc.db).CreateCollection(ctx, collection.Name())
AssertEqualAltError(t, *tc.err, tc.alt, err)
})
}
Expand All @@ -413,7 +412,7 @@ func TestDatabaseName(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
ctx, collection := setup.Setup(t)

err := collection.Database().Client().Database("").CreateCollection(ctx, testutil.CollectionName(t))
err := collection.Database().Client().Database("").CreateCollection(ctx, collection.Name())
expectedErr := driver.InvalidOperationError(driver.InvalidOperationError{MissingField: "Database"})
assert.Equal(t, expectedErr, err)
})
Expand All @@ -422,7 +421,7 @@ func TestDatabaseName(t *testing.T) {
ctx, collection := setup.Setup(t)

dbName63 := strings.Repeat("a", 63)
err := collection.Database().Client().Database(dbName63).CreateCollection(ctx, testutil.CollectionName(t))
err := collection.Database().Client().Database(dbName63).CreateCollection(ctx, collection.Name())
require.NoError(t, err)
collection.Database().Client().Database(dbName63).Drop(ctx)
})
Expand Down
3 changes: 1 addition & 2 deletions integration/commands_administration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/FerretDB/FerretDB/integration/shareddata"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/must"
"github.com/FerretDB/FerretDB/internal/util/testutil"
)

func TestCommandsAdministrationCreateDropList(t *testing.T) {
Expand Down Expand Up @@ -122,7 +121,7 @@ func TestCommandsAdministrationCreateDropListDatabases(t *testing.T) {
assert.Equal(t, bson.D{{"ok", 1.0}}, res)

// there is no explicit command to create database, so create collection instead
err = db.Client().Database(name).CreateCollection(ctx, testutil.CollectionName(t))
err = db.Client().Database(name).CreateCollection(ctx, collection.Name())
require.NoError(t, err)

names, err = db.Client().ListDatabaseNames(ctx, filter)
Expand Down
2 changes: 1 addition & 1 deletion integration/setup/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func startup() {
}

if p := *compatPortF; p == 0 {
zap.S().Warn("Compat system: none, compatibility tests will be skipped.")
zap.S().Infof("Compat system: none, compatibility tests will be skipped.")
} else {
zap.S().Infof("Compat system: port %d.", p)
}
Expand Down
25 changes: 14 additions & 11 deletions integration/setup/setup_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type SetupCompatOpts struct {

// Data providers.
Providers []shareddata.Provider

ownDatabase bool
baseCollectionName string
}

// SetupResult represents compatibility test setup results.
Expand All @@ -63,6 +66,13 @@ func SetupCompatWithOpts(tb testing.TB, opts *SetupCompatOpts) *SetupCompatResul
opts = new(SetupCompatOpts)
}

if opts.DatabaseName == "" {
opts.DatabaseName = testutil.DatabaseName(tb)
opts.ownDatabase = true
}

opts.baseCollectionName = testutil.CollectionName(tb)

ctx, cancel := context.WithCancel(testutil.Ctx(tb))

level := zap.NewAtomicLevelAt(zap.ErrorLevel)
Expand Down Expand Up @@ -112,16 +122,9 @@ func SetupCompat(tb testing.TB) (context.Context, []*mongo.Collection, []*mongo.
func setupCompatCollections(tb testing.TB, ctx context.Context, client *mongo.Client, opts *SetupCompatOpts) []*mongo.Collection {
tb.Helper()

var ownDatabase bool
databaseName := opts.DatabaseName
if databaseName == "" {
databaseName = testutil.DatabaseName(tb)
ownDatabase = true
}

database := client.Database(databaseName)
database := client.Database(opts.DatabaseName)

if ownDatabase {
if opts.ownDatabase {
// drop remnants of the previous failed run
_ = database.Drop(ctx)

Expand All @@ -138,11 +141,11 @@ func setupCompatCollections(tb testing.TB, ctx context.Context, client *mongo.Cl

collections := make([]*mongo.Collection, 0, len(opts.Providers))
for _, provider := range opts.Providers {
collectionName := testutil.CollectionName(tb) + "_" + provider.Name()
collectionName := opts.baseCollectionName + "_" + provider.Name()
if opts.KeepData {
collectionName = strings.ToLower(provider.Name())
}
fullName := databaseName + "." + collectionName
fullName := opts.DatabaseName + "." + collectionName

if *targetPortF == 0 && !slices.Contains(provider.Handlers(), *handlerF) {
tb.Logf(
Expand Down
Loading

0 comments on commit 2d4c31c

Please sign in to comment.