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"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequest(t *testing.T) {
|
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")
|
|
|
|
}
|
|
|
|
}
|