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) +}