-
Notifications
You must be signed in to change notification settings - Fork 9
/
mongopersist_test.go
85 lines (67 loc) · 1.6 KB
/
mongopersist_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package test161
import (
"github.com/stretchr/testify/assert"
"gopkg.in/mgo.v2"
"testing"
"time"
)
// MongoDB test connection
var mongoTestDialInfo = &mgo.DialInfo{
Addrs: []string{"localhost:27017"},
Timeout: 60 * time.Second,
Database: "test",
Username: "",
Password: "",
}
func TestMongoBoot(t *testing.T) {
t.Parallel()
if !testFlagDB {
t.Skip("Skipping MongoDB Test")
}
assert := assert.New(t)
mongo, err := NewMongoPersistence(mongoTestDialInfo)
assert.Nil(err)
assert.NotNil(mongo)
if err != nil {
t.FailNow()
}
defer mongo.Close()
test, err := TestFromString("q")
assert.Nil(err)
assert.Nil(test.MergeConf(TEST_DEFAULTS))
env := defaultEnv.CopyEnvironment()
env.Persistence = mongo
env.RootDir = defaultEnv.RootDir
assert.Nil(env.Persistence.Notify(test, MSG_PERSIST_CREATE, 0))
assert.Nil(test.Run(env))
}
func TestMongoGetUser(t *testing.T) {
t.Parallel()
if !testFlagDB {
t.Skip("Skipping MongoDB Test")
}
assert := assert.New(t)
// MongoDB test connection
var di = &mgo.DialInfo{
Addrs: []string{"localhost:27017"},
Timeout: 60 * time.Second,
Database: "test161",
Username: "",
Password: "",
}
mongo, err := NewMongoPersistence(di)
assert.Nil(err)
assert.NotNil(mongo)
if err != nil {
t.FailNow()
}
defer mongo.Close()
staff := "services.auth0.user_metadata.staff"
who := map[string]interface{}{"services.auth0.email": "[email protected]"}
filter := map[string]interface{}{staff: 1}
res := make([]interface{}, 0)
err = mongo.Retrieve(PERSIST_TYPE_USERS, who, filter, &res)
assert.Nil(err)
assert.True(len(res) > 0)
t.Log(res)
}