forked from zph/moresql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfull_sync_test.go
43 lines (39 loc) · 925 Bytes
/
full_sync_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
package moresql_test
import (
m "github.com/zph/moresql"
. "gopkg.in/check.v1"
"gopkg.in/mgo.v2/bson"
)
func BuildFields(sx ...string) m.Fields {
f := m.Fields{}
for _, s := range sx {
var mon string
if s == "_id" {
mon = "id"
} else {
mon = "string"
}
f[s] = m.Field{
m.Mongo{s, mon},
m.Postgres{s, "string"},
}
}
return f
}
func (s *MySuite) TestBuildOpFromMongo(c *C) {
result := make(map[string]interface{})
id := bson.ObjectId("123")
result["_id"] = id
result["name"] = "Alice"
db := m.DBResult{"user", "user", result}
fields := BuildFields("_id", "name", "age")
coll := m.Collection{"user", "user", fields}
op := m.BuildOpFromMgo([]string{"_id", "name", "age"}, db, coll)
c.Check(op.Id, Equals, id)
c.Check(op.Operation, Equals, "i")
c.Check(op.Data["name"], Equals, "Alice")
if val, ok := op.Data["age"]; ok {
c.Check(ok, Equals, true)
c.Check(val, Equals, nil)
}
}