2024-04-15 23:58:32 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-04-17 18:06:38 +09:00
|
|
|
"encoding/base64"
|
2024-04-15 23:58:32 +09:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2024-04-19 01:31:15 +09:00
|
|
|
"sync"
|
2024-04-15 23:58:32 +09:00
|
|
|
"testing"
|
2024-04-19 01:31:15 +09:00
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/fumiama/terasu/dns"
|
2024-04-15 23:58:32 +09:00
|
|
|
)
|
|
|
|
|
2024-04-19 01:31:15 +09:00
|
|
|
type testlist struct {
|
|
|
|
sync.RWMutex
|
|
|
|
m map[string][]*uintptr
|
|
|
|
}
|
|
|
|
|
2024-04-15 23:58:32 +09:00
|
|
|
func TestRequest(t *testing.T) {
|
2024-04-19 01:31:15 +09:00
|
|
|
(*testlist)(unsafe.Pointer(&dns.IPv4Servers)).m = make(map[string][]*uintptr)
|
|
|
|
(*testlist)(unsafe.Pointer(&dns.IPv6Servers)).m = make(map[string][]*uintptr)
|
2024-05-02 18:53:32 +09:00
|
|
|
dns.IPv4Servers.Add(&dns.DNSConfig{
|
|
|
|
Servers: map[string][]string{
|
|
|
|
"dot.360.cn": {
|
|
|
|
"101.198.192.33:853",
|
|
|
|
"112.65.69.15:853",
|
|
|
|
"101.226.4.6:853",
|
|
|
|
"218.30.118.6:853",
|
|
|
|
"123.125.81.6:853",
|
|
|
|
"140.207.198.6:853",
|
|
|
|
},
|
2024-04-19 01:31:15 +09:00
|
|
|
},
|
|
|
|
})
|
2024-05-02 18:53:32 +09:00
|
|
|
dns.IPv6Servers.Add(&dns.DNSConfig{
|
|
|
|
Servers: map[string][]string{
|
|
|
|
"dot.360.cn": {
|
|
|
|
"101.198.192.33:853",
|
|
|
|
"112.65.69.15:853",
|
|
|
|
"101.226.4.6:853",
|
|
|
|
"218.30.118.6:853",
|
|
|
|
"123.125.81.6:853",
|
|
|
|
"140.207.198.6:853",
|
|
|
|
},
|
2024-04-19 01:31:15 +09:00
|
|
|
},
|
|
|
|
})
|
2024-04-19 00:20:03 +09:00
|
|
|
r := gorequest(`{"code":0,"headers":{"authorization":"Token ","host":"api.mangacopy.com","source":"copyApp","webp":"1","region":"1","version":"2.1.7","platform":"3","user-agent":"COPY/2.1.7"},"method":"GET","url":"https://api.mangacopy.com/api/v3/h5/homeIndex?platform\u003d3"}`)
|
2024-04-15 23:58:32 +09:00
|
|
|
t.Log(r)
|
|
|
|
c := capsule{}
|
|
|
|
err := json.Unmarshal(stringToBytes(r), &c)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if c.C != http.StatusOK {
|
2024-04-17 18:06:38 +09:00
|
|
|
s, err := base64.StdEncoding.DecodeString(c.D)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("status code", c.C, "msg:", c.D)
|
|
|
|
} else {
|
|
|
|
t.Fatal("status code", c.C, "msg:", s)
|
|
|
|
}
|
2024-04-15 23:58:32 +09:00
|
|
|
}
|
|
|
|
if len(c.D) == 0 {
|
|
|
|
t.Fatal("empty data")
|
|
|
|
}
|
|
|
|
}
|