33 lines
767 B
Go
33 lines
767 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",
|
|
DatabaseName: "test_replicaset",
|
|
},
|
|
Timeout: 10 * time.Second,
|
|
})
|
|
assert.NoError(t, err)
|
|
d.Drop(ctx)
|
|
|
|
d2, err := Connect(ctx, &ConnectDeps{
|
|
Configuration: &Configuration{
|
|
URL: "mongodb://test:test@localhost:27020/",
|
|
DatabaseName: "test_default",
|
|
},
|
|
Timeout: 10 * time.Second,
|
|
})
|
|
assert.NoError(t, err)
|
|
d2.Drop(ctx)
|
|
}
|