-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
55 lines (48 loc) · 1.1 KB
/
main_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
package main
import (
"errors"
"github.com/djak250/mgo-wrapper-interface/mongo"
"gopkg.in/mgo.v2/bson"
"testing"
)
// Run with test -v to show the output of right values
func TestRunDbSuite(t *testing.T) {
tmdb := mongo.TMgoDatabase{
"test",
[]*mongo.TMgoCollection{},
t,
}
objId := bson.NewObjectId()
testObj := map[string]interface{}{
"_id": objId,
"test1": "1",
"test2": "2",
"test3": "3",
}
tmdb.ExpectInsert("testCol", nil)
testObjBson := bson.M{
"_id": objId,
"test1": "1",
"test2": "2",
"test3": "3",
}
testObjBsonSlice := []bson.M{testObjBson}
tmdb.ExpectFind("testCol", testObjBson, testObjBsonSlice)
tmdb.ExpectUpdate("testCol", nil)
testObj2Bson := bson.M{
"_id": objId,
"test1": "1",
"test2": "2",
"test3": "3",
"updated": true,
}
testObjBsonSlice2 := []bson.M{testObj2Bson}
tmdb.ExpectFind("testCol", testObj2Bson, testObjBsonSlice2)
tmdb.ExpectRemove("testCol", nil)
tmdb.ExpectFind("testCol", errors.New("not found"), errors.New("not found"))
tms := mongo.TMgoSession{
[]*mongo.TMgoDatabase{&tmdb},
t,
}
runDbSuite(tms, testObj)
}