Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
noisersup committed May 16, 2024
1 parent 3f4e1f4 commit 401e818
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 139 deletions.
79 changes: 58 additions & 21 deletions ferretdb/ferretdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,34 +148,71 @@ func Example_tls() {
}

func TestEmbedded(t *testing.T) {
f, err := ferretdb.New(&ferretdb.Config{
Listener: ferretdb.ListenerConfig{
TCP: "127.0.0.1:0",
t.Parallel()

for name, tc := range map[string]struct {
config *ferretdb.Config
}{
"TCP": {
config: &ferretdb.Config{
Listener: ferretdb.ListenerConfig{
TCP: "127.0.0.1:0",
},
Handler: "postgresql",
PostgreSQLURL: "postgres://username@127.0.0.1:5432/ferretdb?search_path=",
},
},
Handler: "postgresql",
PostgreSQLURL: "postgres://username@127.0.0.1:5432/ferretdb?search_path=",
})
require.NoError(t, err)
"TLS": {
config: &ferretdb.Config{
Listener: ferretdb.ListenerConfig{
TCP: "127.0.0.1:0",

// Use `setup.Dir`.
// TODO https://github.com/FerretDB/FerretDB/issues/2062
TLSCertFile: "",
TLSKeyFile: "",
TLSCAFile: "",
},
Handler: "postgresql",
PostgreSQLURL: "postgres://username@127.0.0.1:5432/ferretdb?search_path=",
},
},
"OldName": {
config: &ferretdb.Config{
Listener: ferretdb.ListenerConfig{
TCP: "127.0.0.1:0",
},
Handler: "pg",
PostgreSQLURL: "postgres://username@127.0.0.1:5432/ferretdb?search_path=",
},
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
f, err := ferretdb.New(tc.config)
require.NoError(t, err)

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

done := make(chan struct{})
done := make(chan struct{})

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

uri := f.MongoDBURI()
uri := f.MongoDBURI()

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

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

_, err = client.Database(dbName).Collection(collName).InsertOne(ctx, bson.M{"foo": "bar"})
require.NoError(t, err)
_, err = client.Database(dbName).Collection(collName).InsertOne(ctx, bson.M{"foo": "bar"})

Check failure on line 211 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)
require.NoError(t, err)

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

This file was deleted.

0 comments on commit 401e818

Please sign in to comment.