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

Fix embedded package panic #4278

Merged
merged 16 commits into from
May 16, 2024
4 changes: 3 additions & 1 deletion ferretdb/ferretdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ func New(config *Config) (*FerretDB, error) {

SQLiteURL: config.SQLiteURL,

//nolint:mnd // Command-line default flags
TestOpts: registry.TestOpts{
CappedCleanupPercentage: 10, // handler expects it to be a non-zero value
CappedCleanupPercentage: 10,
BatchSize: 100,
},
})
if err != nil {
Expand Down
41 changes: 41 additions & 0 deletions ferretdb/ferretdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ import (
"fmt"
"log"
"path/filepath"
"testing"

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

"github.com/FerretDB/FerretDB/ferretdb"
"github.com/FerretDB/FerretDB/internal/util/testutil"
)

func Example_tcp() {
Expand Down Expand Up @@ -139,3 +146,37 @@ func Example_tls() {

// Output: mongodb://127.0.0.1:17028/?tls=true
}

func TestEmbedded(t *testing.T) {
ctx, cancel := context.WithCancel(testutil.Ctx(t))

f, err := ferretdb.New(&ferretdb.Config{
Listener: ferretdb.ListenerConfig{
TCP: "127.0.0.1:0",
},
Handler: "postgresql",
PostgreSQLURL: testutil.TestPostgreSQLURI(t, ctx, "postgres://username@127.0.0.1:5432/ferretdb?search_path="),
})
require.NoError(t, err)

done := make(chan struct{})

go func() {
require.NoError(t, f.Run(ctx))
close(done)
}()

uri := f.MongoDBURI()

client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
require.NoError(t, err)

dbName, collName := testutil.DatabaseName(t), testutil.CollectionName(t)

//nolint:forbidigo // bson is required to use the driver
_, err = client.Database(dbName).Collection(collName).InsertOne(ctx, bson.M{"foo": "bar"})
require.NoError(t, err)

cancel()
<-done
}
118 changes: 0 additions & 118 deletions integration/embedded_test.go

This file was deleted.