Files
libkiwi/libkiwi_test.go
y a t s 0bfe254d05 Fix string bounds issue
Better hostname handling
2024-09-02 11:08:50 -04:00

72 lines
1.3 KiB
Go

package libkiwi
import (
"context"
"log"
"net/http"
"net/url"
"os"
"testing"
)
const TEST_HOST = "kiwifarms.st"
func TestGetPage(t *testing.T) {
cookies := os.Getenv("TEST_COOKIES")
kf, err := NewKF(http.Client{}, TEST_HOST, cookies)
if err != nil {
t.Error(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.Println("Getting homepage")
resp, err := kf.GetPage(ctx, kf.domain)
if err != nil {
t.Error(err)
}
defer resp.Body.Close()
log.Printf("Response status code: %d\n", resp.StatusCode)
for k, v := range resp.Header {
if len(v) > 0 {
log.Printf("%s: %s\n", k, v[0])
}
}
}
func TestRefreshSession(t *testing.T) {
cookies := os.Getenv("TEST_COOKIES")
kf, err := NewKF(http.Client{}, TEST_HOST, cookies)
if err != nil {
t.Error(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.Println("Refreshing xf_session")
tk, err := kf.RefreshSession(ctx)
if err != nil {
t.Error(err)
}
log.Println("New xf_session token: " + tk)
}
func TestCookieString(t *testing.T) {
cookies := os.Getenv("TEST_COOKIES")
kf, err := NewKF(http.Client{}, TEST_HOST, cookies)
if err != nil {
t.Error(err)
}
u, err := url.Parse("https://" + TEST_HOST)
if err != nil {
t.Error(err)
}
log.Println("Cookies from jar: " + kf.Client.Jar.(*KiwiJar).CookieString(u))
}