-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuseragent_test.go
More file actions
53 lines (41 loc) · 1.06 KB
/
useragent_test.go
File metadata and controls
53 lines (41 loc) · 1.06 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
package useragent
import (
"testing"
"github.com/sohaha/zlsgo"
"github.com/zlsgo/useragent/types"
)
func TestParse(t *testing.T) {
tt := zlsgo.NewTest(t)
ua := "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0"
result, err := Parse(ua)
tt.NoError(err)
tt.Equal(types.BrowserFirefox, result.Browser().Type)
tt.Equal(types.OSWindows, result.OS().Type)
tt.Equal(types.DeviceDesktop, result.Device().Type)
}
func TestGenerate(t *testing.T) {
tt := zlsgo.NewTest(t)
ua, err := Generate(&types.GenerateOptions{
BrowserOpt: types.BrowserOptions{
Type: types.BrowserChrome,
Version: types.Version{Major: 91, Minor: 0, Patch: 4472},
},
OSOpt: types.OSOptions{
Type: types.OSWindows,
Version: types.Version{Major: 10, Minor: 0},
},
DeviceOpt: types.DeviceOptions{
Type: types.DeviceDesktop,
Brand: "Generic",
Model: "PC",
},
})
tt.NoError(err)
tt.Log(ua)
}
func TestGenerateRand(t *testing.T) {
tt := zlsgo.NewTest(t)
ua, err := GenerateRand(types.DeviceDesktop)
tt.NoError(err)
tt.Log(ua)
}