96 lines
1.8 KiB
Go
96 lines
1.8 KiB
Go
package server
|
|
|
|
import (
|
|
`encoding/json`
|
|
`encoding/xml`
|
|
`fmt`
|
|
"testing"
|
|
|
|
`github.com/davecgh/go-spew/spew`
|
|
`github.com/goccy/go-yaml`
|
|
)
|
|
|
|
func TestNewClient(t *testing.T) {
|
|
|
|
var err error
|
|
var b []byte
|
|
var r *R00tClient
|
|
|
|
for _, s := range []string{
|
|
"Mozilla/5.0 " +
|
|
"(X11; Linux x86_64) " +
|
|
"AppleWebKit/537.36 " +
|
|
"(KHTML, like Gecko) " +
|
|
"Chrome/131.0.0.0 " +
|
|
"Safari/537.36", // Chrome
|
|
"Mozilla/5.0 " +
|
|
"(X11; Linux x86_64; rv:133.0) " +
|
|
"Gecko/20100101 " +
|
|
"Firefox/133.0", // Firefox
|
|
"curl/8.11.0", // Curl
|
|
"Wget/1.25.0", // Wget
|
|
} {
|
|
t.Logf("Raw UA: '%s'\n\n", s)
|
|
if r, err = NewClient(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if b, err = json.Marshal(r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(b))
|
|
t.Logf("R00tClient:\n%s\n\n\n", spew.Sdump(r))
|
|
}
|
|
}
|
|
|
|
func TestExplicitContent(t *testing.T) {
|
|
|
|
var b []byte
|
|
var err error
|
|
var r *R00tClient = &R00tClient{
|
|
ClientVer: &Ver{
|
|
Major: 1,
|
|
Minor: 2,
|
|
Patch: 3,
|
|
},
|
|
OSVer: &Ver{
|
|
Major: 9,
|
|
Minor: 8,
|
|
Patch: 7,
|
|
},
|
|
URL: new(string),
|
|
String: new(string),
|
|
Name: new(string),
|
|
ClientVerStr: new(string),
|
|
OS: new(string),
|
|
OsVerStr: new(string),
|
|
Dev: new(string),
|
|
IsMobile: false,
|
|
IsTablet: false,
|
|
IsDesktop: false,
|
|
IsBot: false,
|
|
}
|
|
|
|
*r.URL = "https://datatracker.ietf.org/doc/html/rfc2324.html"
|
|
*r.String = "(COMPLETE USER AGENT STRING)"
|
|
*r.Name = "coffee_pot"
|
|
*r.ClientVerStr = "1.2.3"
|
|
*r.OS = "JavaOS"
|
|
*r.OsVerStr = "9.8.7"
|
|
*r.Dev = "mocha-latte"
|
|
|
|
if b, err = json.MarshalIndent(r, "", " "); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(b))
|
|
|
|
if b, err = xml.Marshal(r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(b))
|
|
|
|
if b, err = yaml.Marshal(r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(b))
|
|
}
|