-
Notifications
You must be signed in to change notification settings - Fork 6
/
crawler_google_test.go
212 lines (209 loc) · 13.1 KB
/
crawler_google_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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* This file is auto-generated! Any changes to this file will be lost! */
package woothee
import (
"testing"
)
func Test_crawler_google(t *testing.T) {
var result *Result
var err error
result, err = Parse(`Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`)
if err != nil {
t.Errorf(`Failed to parse 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`, result.Category)
}
if result.Name != "Googlebot" {
t.Errorf("Expected result.Name for '%s' to be 'Googlebot', but got '%s'", `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`, result.Version)
}
}
result, err = Parse(`Googlebot-Image/1.0`)
if err != nil {
t.Errorf(`Failed to parse 'Googlebot-Image/1.0': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `Googlebot-Image/1.0`, result.Category)
}
if result.Name != "Googlebot" {
t.Errorf("Expected result.Name for '%s' to be 'Googlebot', but got '%s'", `Googlebot-Image/1.0`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `Googlebot-Image/1.0`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `Googlebot-Image/1.0`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `Googlebot-Image/1.0`, result.Version)
}
}
result, err = Parse(`DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`)
if err != nil {
t.Errorf(`Failed to parse 'DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Category)
}
if result.Name != "Googlebot Mobile" {
t.Errorf("Expected result.Name for '%s' to be 'Googlebot Mobile', but got '%s'", `DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Version)
}
}
result, err = Parse(`SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`)
if err != nil {
t.Errorf(`Failed to parse 'SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Category)
}
if result.Name != "Googlebot Mobile" {
t.Errorf("Expected result.Name for '%s' to be 'Googlebot Mobile', but got '%s'", `SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)`, result.Version)
}
}
result, err = Parse(`DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)`)
if err != nil {
t.Errorf(`Failed to parse 'DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)`, result.Category)
}
if result.Name != "Google Mediapartners" {
t.Errorf("Expected result.Name for '%s' to be 'Google Mediapartners', but got '%s'", `DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `DoCoMo/2.0 SH905i(c100;TB;W24H16) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)`, result.Version)
}
}
result, err = Parse(`Mediapartners-Google`)
if err != nil {
t.Errorf(`Failed to parse 'Mediapartners-Google': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `Mediapartners-Google`, result.Category)
}
if result.Name != "Google Mediapartners" {
t.Errorf("Expected result.Name for '%s' to be 'Google Mediapartners', but got '%s'", `Mediapartners-Google`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `Mediapartners-Google`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `Mediapartners-Google`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `Mediapartners-Google`, result.Version)
}
}
result, err = Parse(`Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)`)
if err != nil {
t.Errorf(`Failed to parse 'Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)`, result.Category)
}
if result.Name != "Google Feedfetcher" {
t.Errorf("Expected result.Name for '%s' to be 'Google Feedfetcher', but got '%s'", `Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; feed-id=000000000000000000)`, result.Version)
}
}
result, err = Parse(`AppEngine-Google`)
if err != nil {
t.Errorf(`Failed to parse 'AppEngine-Google': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `AppEngine-Google`, result.Category)
}
if result.Name != "Google AppEngine" {
t.Errorf("Expected result.Name for '%s' to be 'Google AppEngine', but got '%s'", `AppEngine-Google`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `AppEngine-Google`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `AppEngine-Google`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `AppEngine-Google`, result.Version)
}
}
result, err = Parse(`Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13`)
if err != nil {
t.Errorf(`Failed to parse 'Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13`, result.Category)
}
if result.Name != "Google Web Preview" {
t.Errorf("Expected result.Name for '%s' to be 'Google Web Preview', but got '%s'", `Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13`, result.Version)
}
}
result, err = Parse(`FeedBurner/1.0 (http://www.FeedBurner.com)`)
if err != nil {
t.Errorf(`Failed to parse 'FeedBurner/1.0 (http://www.FeedBurner.com)': %s`, err)
} else {
if result.Category != "crawler" {
t.Errorf("Expected result.Category for '%s' to be 'crawler', but got '%s'", `FeedBurner/1.0 (http://www.FeedBurner.com)`, result.Category)
}
if result.Name != "Google FeedBurner" {
t.Errorf("Expected result.Name for '%s' to be 'Google FeedBurner', but got '%s'", `FeedBurner/1.0 (http://www.FeedBurner.com)`, result.Name)
}
if true && result.Os != "UNKNOWN" {
t.Errorf("Expected result.Os for '%s' to be 'UNKNOWN', but got '%s'", `FeedBurner/1.0 (http://www.FeedBurner.com)`, result.Os)
}
if false && result.OsVersion != "UNKNOWN" {
t.Errorf("Expected result.OsVersion for '%s' to be 'UNKNOWN', but got '%s'", `FeedBurner/1.0 (http://www.FeedBurner.com)`, result.OsVersion)
}
if false && result.Version != "UNKNOWN" {
t.Errorf("Expected result.Version for '%s' to be 'UNKNOWN', but got '%s'", `FeedBurner/1.0 (http://www.FeedBurner.com)`, result.Version)
}
}
}