-
Notifications
You must be signed in to change notification settings - Fork 0
/
yahb_test.go
121 lines (99 loc) · 2.21 KB
/
yahb_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
package yahb
import (
"io/ioutil"
"log"
"testing"
)
var placeBuf, _ = ioutil.ReadFile("./testdata/place.json")
var placeObj = new(Place)
var settingsBuf, _ = ioutil.ReadFile("./testdata/setting.json")
var settingsObj = new(Setting)
var reqBuf, _ = ioutil.ReadFile("./testdata/req.json")
var reqObj = new(BidRequest)
func _testPlaceUnmarshalJSON(t *testing.T) {
err := placeObj.UnmarshalJSON(placeBuf)
if err != nil {
t.Fatal(err)
}
}
func _testPlaceValidate(t *testing.T) {
err := placeObj.Validate()
if err != nil {
t.Fatal(err)
}
}
func TestPlace(t *testing.T) {
t.Parallel()
_testPlaceUnmarshalJSON(t)
_testPlaceValidate(t)
}
func _testSettingsUnmarshalJSON(t *testing.T) {
err := settingsObj.UnmarshalJSON(settingsBuf)
if err != nil {
t.Fatal(err)
}
}
func _testSettingsValidate(t *testing.T) {
err := settingsObj.Validate()
if err != nil {
t.Fatal(err)
}
}
func TestSettings(t *testing.T) {
t.Parallel()
_testSettingsUnmarshalJSON(t)
_testSettingsValidate(t)
}
func _testBidRequestUnmarshalJSON(t *testing.T) {
err := reqObj.UnmarshalJSON(reqBuf)
if err != nil {
t.Fatal(err)
}
}
func _testBidRequestValidate(t *testing.T) {
err := reqObj.Validate()
if err != nil {
t.Fatal(err)
}
}
func TestBidRequest(t *testing.T) {
t.Parallel()
_testBidRequestUnmarshalJSON(t)
_testBidRequestValidate(t)
}
func BenchmarkBidRequest_MarshalJSON(b *testing.B) {
bidReq := new(BidRequest)
bidReq.Setting = &Setting{
Currency: "RUB",
WinSize: &Size{
Width: 100,
Height: 100,
},
}
bidReq.Places = append(bidReq.Places, Place{
ID: "1",
PlacementId: "1",
Sizes: [][]int{[]int{100, 100}, []int{200, 200}},
})
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, e := bidReq.MarshalJSON()
if e != nil {
b.Fatal(e)
}
}
})
}
func BenchmarkBidRequest_UnMarshalJSON(b *testing.B) {
buf := []byte("{\"places\":[{\"id\":\"1\",\"placementId\":\"1\",\"sizes\":[[100,100],[200,200]]}],\"settings\":{\"currency\":\"RUB\",\"windowSize\":{\"width\":100,\"height\":100}}}")
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
bidReq := new(BidRequest)
log.Fatal(string(buf))
e := bidReq.UnmarshalJSON(buf)
if e != nil {
b.Fatal(e)
}
}
})
}