This commit is contained in:
VnPower
2023-08-28 11:11:52 +07:00
parent 7593712810
commit f4c2f6be32
2 changed files with 72 additions and 66 deletions
+2 -1
View File
@@ -3,5 +3,6 @@ steps:
image: golang
commands:
- go get
- go run main.go
- go run main.go &
- go test -v
secrets: [pixivfe_token]
+70 -65
View File
@@ -2,82 +2,87 @@ package main
import (
"net/http"
"os"
"pixivfe/handler"
"testing"
"time"
)
func generate_test_client() *handler.PixivClient {
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
client := &http.Client{
Timeout: time.Duration(5000) * time.Millisecond,
Transport: transport,
}
// func generate_test_client() *handler.PixivClient {
// transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
// client := &http.Client{
// Timeout: time.Duration(5000) * time.Millisecond,
// Transport: transport,
// }
pc := &handler.PixivClient{
Client: client,
Header: make(map[string]string),
Cookie: make(map[string]string),
Lang: "en",
}
// pc := &handler.PixivClient{
// Client: client,
// Header: make(map[string]string),
// Cookie: make(map[string]string),
// Lang: "en",
// }
pc.SetSessionID(os.Getenv("PIXIVFE_TOKEN"))
pc.SetUserAgent("Mozilla/5.0")
// pc.SetSessionID(os.Getenv("PIXIVFE_TOKEN"))
// pc.SetUserAgent("Mozilla/5.0")
return pc
}
// return pc
// }
func Test_GetArtworkByID(t *testing.T) {
client := generate_test_client()
// func Test_GetArtworkByID(t *testing.T) {
// client := generate_test_client()
start := time.Now()
_, err := client.GetArtworkByID("97422582")
end := time.Since(start).Seconds()
// start := time.Now()
// _, err := client.GetArtworkByID("97422582")
// end := time.Since(start).Seconds()
// if err != nil {
// t.Error(err)
// }
// t.Logf("Took %.2f seconds", end)
// }
// func Test_GetArtworkImages(t *testing.T) {
// client := generate_test_client()
// start := time.Now()
// _, err := client.GetArtworkImages("97422582")
// end := time.Since(start).Seconds()
// if err != nil {
// t.Error(err)
// }
// t.Logf("Took %.2f seconds", end)
// }
// func Test_GetArtworkComments(t *testing.T) {
// client := generate_test_client()
// start := time.Now()
// _, err := client.GetArtworkComments("97422582")
// end := time.Since(start).Seconds()
// if err != nil {
// t.Error(err)
// }
// t.Logf("Took %.2f seconds", end)
// }
// func Test_GetRelatedArtworks(t *testing.T) {
// client := generate_test_client()
// start := time.Now()
// _, err := client.GetRelatedArtworks("97422582")
// end := time.Since(start).Seconds()
// if err != nil {
// t.Error(err)
// }
// t.Logf("Took %.2f seconds", end)
// }
func Test_Main(t *testing.T) {
_, err := http.Get("http://localhost:8282/")
if err != nil {
t.Error(err)
}
t.Logf("Took %.2f seconds", end)
}
func Test_GetArtworkImages(t *testing.T) {
client := generate_test_client()
start := time.Now()
_, err := client.GetArtworkImages("97422582")
end := time.Since(start).Seconds()
if err != nil {
t.Error(err)
}
t.Logf("Took %.2f seconds", end)
}
func Test_GetArtworkComments(t *testing.T) {
client := generate_test_client()
start := time.Now()
_, err := client.GetArtworkComments("97422582")
end := time.Since(start).Seconds()
if err != nil {
t.Error(err)
}
t.Logf("Took %.2f seconds", end)
}
func Test_GetRelatedArtworks(t *testing.T) {
client := generate_test_client()
start := time.Now()
_, err := client.GetRelatedArtworks("97422582")
end := time.Since(start).Seconds()
if err != nil {
t.Error(err)
}
t.Logf("Took %.2f seconds", end)
t.Logf("/ passed")
}
// func Test_GetArtworkGoroutine(t *testing.T) {