-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_test.go
131 lines (109 loc) · 2.14 KB
/
data_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package bconv
import (
"gopkg.in/mgo.v2/bson"
"testing"
)
type Person struct {
Name string
}
var (
testBson2 = &bson.M{
"Name": "SHAALX",
}
testJson2 = &Person{
Name: "SHAALX ?",
}
)
func log_err(err error, t *testing.T) {
if isError(err) {
t.Error(err)
}
}
func TestBson2BsonBytes(t *testing.T) {
b, err := Bson2BsonBytes(testBson2)
log_err(err, t)
t.Log(b)
t.Log(string(b)) // error string
retBson, err := BsonBytes2Bson(b)
log_err(err, t)
t.Log(retBson)
}
func TestBson2JsonBytes(t *testing.T) {
b, err := Bson2JsonBytes(testBson2)
log_err(err, t)
t.Log(b)
t.Log(string(b)) //ok
retBson, err := JsonBytes2Bson(b)
log_err(err, t)
t.Log(retBson)
}
func TestJson2JsonBytes(t *testing.T) {
p := Person{Name: "IS SHAALX ?"}
b, err := Json2JsonBytes(p)
log_err(err, t)
t.Log(b)
t.Log(string(b))
var j interface{}
JsonBytes2Json(b, &j)
log_err(err, t)
t.Logf("%#v", j)
}
// // failed
// func TestJson2BsonBytes(t *testing.T) {
// p := Person{Name: "IS SHAALX."}
// b, err := _Json2BsonBytes(p)
// log_err(err, t)
// t.Log(b)
// t.Log(string(b))
// var j interface{}
// _BsonBytes2Json(b, &j)
// log_err(err, t)
// t.Logf("%#v", j)
// }
func TestBson2Json(t *testing.T) {
var j Person
err := Bson2Json(testBson2, &j)
log_err(err, t)
t.Logf("%#v", j)
bson_, err := Json2Bson(j)
log_err(err, t)
t.Logf("%#v", bson_)
}
// // failed
// func TestBson2Json_(t *testing.T) {
// var j Person
// err := _Bson2Json(testBson, &j)
// log_err(err, t)
// t.Logf("%#v", j)
// bson_, err := Json2Bson(j)
// log_err(err, t)
// t.Logf("%#v", bson_)
// }
func TestJson2Bson(t *testing.T) {
bson_, err := Json2Bson(testJson2)
log_err(err, t)
t.Logf("%#v", bson_)
var p Person
Bson2Json(bson_, &p)
log_err(err, t)
t.Logf("%#v", p)
}
// // failed
// func TestJson2Bson_(t *testing.T) {
// bson_, err := _Json2Bson(testJson)
// log_err(err, t)
// t.Logf("%#v", bson_)
// var p Person
// Bson2Json(bson_, &p)
// log_err(err, t)
// t.Logf("%#v", p)
// }
func TestI2I(t *testing.T) {
var p Person
err := I2I(testJson2, &p)
log_err(err, t)
t.Logf("%#v", p)
err = I2I(testBson2, &p)
log_err(err, t)
t.Logf("%#v", p)
}