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 @@

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,

Check warning on line 140 in ferretdb/ferretdb.go

View check run for this annotation

Codecov / codecov/patch

ferretdb/ferretdb.go#L139-L140

Added lines #L139 - L140 were not covered by tests
},
})
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions ferretdb/ferretdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"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"
)
Expand Down Expand Up @@ -139,3 +145,34 @@

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

func TestFerretDB(t *testing.T) {
f, err := ferretdb.New(&ferretdb.Config{
Listener: ferretdb.ListenerConfig{
TCP: "127.0.0.1:0",
},
Handler: "sqlite",
SQLiteURL: "file:./?mode=memory",
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
})
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())

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)

_, err = client.Database("test").Collection("test").InsertOne(ctx, bson.M{"foo": "bar"})

Check failure on line 173 in ferretdb/ferretdb_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

use of `bson.M` forbidden because "Use `*types.Document` instead." (forbidigo)
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

cancel()
<-done
}