-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_schema_test.go
More file actions
163 lines (143 loc) · 5.87 KB
/
benchmark_schema_test.go
File metadata and controls
163 lines (143 loc) · 5.87 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package purejson
import (
"encoding/json"
"testing"
)
type benchTwitterRow struct {
SearchMetadata benchTwitterSearchMetadata `json:"search_metadata"`
Statuses []benchTwitterStatus `json:"statuses"`
}
type benchTwitterSearchMetadata struct {
Count int64 `json:"count"`
MaxID int64 `json:"max_id"`
NextResults string `json:"next_results"`
Query string `json:"query"`
}
type benchTwitterStatus struct {
CreatedAt string `json:"created_at"`
Entities benchTwitterEntities `json:"entities"`
FavoriteCount int64 `json:"favorite_count"`
Favorited bool `json:"favorited"`
ID int64 `json:"id"`
RetweetCount int64 `json:"retweet_count"`
Retweeted bool `json:"retweeted"`
Text string `json:"text"`
User benchTwitterUser `json:"user"`
}
type benchTwitterEntities struct {
Hashtags []benchTwitterHashtag `json:"hashtags"`
UserMentions []benchTwitterUserMention `json:"user_mentions"`
}
type benchTwitterHashtag struct {
Indices []int `json:"indices"`
Text string `json:"text"`
}
type benchTwitterUserMention struct {
ID int64 `json:"id"`
IDStr string `json:"id_str"`
Indices []int `json:"indices"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
}
type benchTwitterUser struct {
ID int64 `json:"id"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
Verified bool `json:"verified"`
}
type benchCITMRow struct {
AreaNames map[string]string `json:"areaNames"`
AudienceSubCategoryNames map[string]string `json:"audienceSubCategoryNames"`
BlockNames map[string]string `json:"blockNames"`
Events map[string]benchCITMEvent `json:"events"`
Performances []benchCITMPerformance `json:"performances"`
SeatCategoryNames map[string]string `json:"seatCategoryNames"`
SubTopicNames map[string]string `json:"subTopicNames"`
SubjectNames map[string]string `json:"subjectNames"`
TopicNames map[string]string `json:"topicNames"`
TopicSubTopics map[string][]int64 `json:"topicSubTopics"`
VenueNames map[string]string `json:"venueNames"`
}
type benchCITMEvent struct {
Description string `json:"description"`
ID int64 `json:"id"`
Logo string `json:"logo"`
Name string `json:"name"`
SubTopicIDs []int64 `json:"subTopicIds"`
SubjectCode string `json:"subjectCode"`
Subtitle string `json:"subtitle"`
TopicIDs []int64 `json:"topicIds"`
}
type benchCITMPerformance struct {
EventID int64 `json:"eventId"`
ID int64 `json:"id"`
Logo string `json:"logo"`
Name string `json:"name"`
Prices []benchCITMPrice `json:"prices"`
SeatCategories []benchCITMSeatCategory `json:"seatCategories"`
SeatMapImage string `json:"seatMapImage"`
Start int64 `json:"start"`
VenueCode string `json:"venueCode"`
}
type benchCITMPrice struct {
Amount int64 `json:"amount"`
AudienceSubCategoryID int64 `json:"audienceSubCategoryId"`
SeatCategoryID int64 `json:"seatCategoryId"`
}
type benchCITMSeatCategory struct {
Areas []benchCITMArea `json:"areas"`
SeatCategoryID int64 `json:"seatCategoryId"`
}
type benchCITMArea struct {
AreaID int64 `json:"areaId"`
BlockIDs []int64 `json:"blockIds"`
}
type benchCanadaRow struct {
Features []benchCanadaFeature `json:"features"`
Type string `json:"type"`
}
type benchCanadaFeature struct {
Geometry benchCanadaGeometry `json:"geometry"`
Properties benchCanadaProperties `json:"properties"`
Type string `json:"type"`
}
type benchCanadaGeometry struct {
Coordinates [][][]float64 `json:"coordinates"`
Type string `json:"type"`
}
type benchCanadaProperties struct {
Name string `json:"name"`
}
func TestBenchmarkSchemaDecodesFixtures(t *testing.T) {
for _, fixtureName := range []string{benchmarkFixtureTwitter, benchmarkFixtureCITM, benchmarkFixtureCanada} {
value, err := benchmarkDecodeSharedSchema(json.Unmarshal, fixtureName, loadBenchmarkFixture(t, fixtureName))
if err != nil {
t.Fatalf("benchmarkDecodeSharedSchema(%s): %v", fixtureName, err)
}
switch row := value.(type) {
case benchTwitterRow:
if row.SearchMetadata.MaxID == 0 || row.SearchMetadata.Query == "" || len(row.Statuses) == 0 {
t.Fatalf("twitter schema decoded sparse root: %+v", row.SearchMetadata)
}
if row.Statuses[0].ID == 0 || row.Statuses[0].User.ID == 0 || row.Statuses[0].User.ScreenName == "" {
t.Fatalf("twitter schema decoded sparse first status: %+v", row.Statuses[0])
}
case benchCITMRow:
if len(row.AreaNames) == 0 || len(row.Events) == 0 || len(row.Performances) == 0 {
t.Fatalf("CITM schema decoded sparse root: areas=%d events=%d performances=%d", len(row.AreaNames), len(row.Events), len(row.Performances))
}
if row.Performances[0].ID == 0 || row.Performances[0].EventID == 0 || len(row.Performances[0].Prices) == 0 {
t.Fatalf("CITM schema decoded sparse first performance: %+v", row.Performances[0])
}
case benchCanadaRow:
if row.Type == "" || len(row.Features) == 0 {
t.Fatalf("Canada schema decoded sparse root: type=%q features=%d", row.Type, len(row.Features))
}
if row.Features[0].Type == "" || row.Features[0].Geometry.Type == "" || len(row.Features[0].Geometry.Coordinates) == 0 {
t.Fatalf("Canada schema decoded sparse first feature: %+v", row.Features[0])
}
default:
t.Fatalf("benchmarkDecodeSharedSchema(%s) returned %T", fixtureName, value)
}
}
}