common/mongo/mongo_test.go

39 lines
909 B
Go

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