-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathclient_test.go
71 lines (60 loc) · 1.5 KB
/
client_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package lungo
import (
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
func TestOpenGoroutineLeak(t *testing.T) {
num := runtime.NumGoroutine()
for i := 0; i < 10; i++ {
_, engine, err := Open(nil, Options{
Store: NewMemoryStore(),
})
assert.NoError(t, err)
engine.Close()
}
assert.Equal(t, num, runtime.NumGoroutine())
}
func TestClientListDatabasesAndNames(t *testing.T) {
clientTest(t, func(t *testing.T, c IClient) {
err := c.Database(testDB).Drop(nil)
assert.NoError(t, err)
names, err := c.ListDatabaseNames(nil, bson.M{
"name": testDB,
})
assert.NoError(t, err)
assert.Equal(t, []string{}, names)
res, err := c.ListDatabases(nil, bson.M{
"name": testDB,
})
assert.NoError(t, err)
assert.Equal(t, mongo.ListDatabasesResult{
Databases: make([]mongo.DatabaseSpecification, 0),
}, res)
_, err = c.Database(testDB).Collection("foo").InsertOne(nil, bson.M{
"name": testDB,
})
assert.NoError(t, err)
names, err = c.ListDatabaseNames(nil, bson.M{
"name": testDB,
})
assert.NoError(t, err)
assert.Equal(t, []string{testDB}, names)
res, err = c.ListDatabases(nil, bson.M{
"name": testDB,
})
assert.NoError(t, err)
assert.Equal(t, mongo.ListDatabasesResult{
Databases: []mongo.DatabaseSpecification{
{
Name: testDB,
SizeOnDisk: res.Databases[0].SizeOnDisk,
Empty: false,
},
},
TotalSize: res.TotalSize,
}, res)
})
}