forked from qiniu/qmgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_test.go
38 lines (31 loc) · 848 Bytes
/
database_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package qmgo
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestDatabase(t *testing.T) {
ast := require.New(t)
var sTimeout int64 = 500000
var cTimeout int64 = 3000
var maxPoolSize uint64 = 3000
collName := "testopen"
dbName := "mongoxtest"
cfg := Config{
Uri: "mongodb://localhost:27017",
Database: dbName,
Coll: collName,
ConnectTimeoutMS: &cTimeout,
SocketTimeoutMS: &sTimeout,
MaxPoolSize: &maxPoolSize,
}
c, err := NewClient(context.Background(), &cfg)
ast.NoError(err)
cli := c.Database(cfg.Database)
ast.Nil(err)
ast.Equal(dbName, cli.GetDatabaseName())
coll := cli.Collection(collName)
ast.Equal(collName, coll.GetCollectionName())
cli.Collection(collName).DropCollection(context.Background())
cli.DropDatabase(context.Background())
}