From 3ec559676d8b28b1b649792dd73a48ca19597ece Mon Sep 17 00:00:00 2001 From: Pasha Date: Thu, 28 Nov 2024 18:49:46 +0300 Subject: [PATCH] added test for connect mongo replicaset and default --- mongo/mongo_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 mongo/mongo_test.go diff --git a/mongo/mongo_test.go b/mongo/mongo_test.go new file mode 100644 index 0000000..4efb188 --- /dev/null +++ b/mongo/mongo_test.go @@ -0,0 +1,38 @@ +package mongo + +import ( + "context" + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +func TestConnectMongo(t *testing.T) { + ctx, cancel := context.WithTimeout(context.TODO(), 15*time.Second) + defer cancel() + d, err := Connect(ctx, &ConnectDeps{ + Configuration: &Configuration{ + URL: "mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs0&readPreference=primary&ssl=false", + User: "test", + Password: "test", + Auth: "admin", + DatabaseName: "test_replicaset", + }, + Timeout: 10 * time.Second, + }) + assert.NoError(t, err) + d.Drop(ctx) + + d2, err := Connect(ctx, &ConnectDeps{ + Configuration: &Configuration{ + URL: "mongodb://localhost:27020/", + User: "test", + Password: "test", + Auth: "admin", + DatabaseName: "test_default", + }, + Timeout: 10 * time.Second, + }) + assert.NoError(t, err) + d2.Drop(ctx) +}