little bit tests

This commit is contained in:
Deerain 2026-10-29 01:42:44 +03:00
parent ed1d845933
commit 17cc791c86

58
playtogo/client_test.go Normal file
View file

@ -0,0 +1,58 @@
package playtogo
import (
"context"
"crypto/rand"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func ApiClient_TokenTestAuth_Success(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Authorization")
valData := strings.Split(token, " ")
if len(valData) == 2 ||
strings.Contains(strings.ToLower(valData[0]), "authorization") ||
len(valData[1]) > 5 {
w.WriteHeader(http.StatusOK)
return
}
w.WriteHeader(http.StatusUnauthorized)
}))
defer testServer.Close()
client := &Client{
baseURL: testServer.URL,
token: rand.Text(),
httpClient: testServer.Client(),
}
_, err := client.GetDomains(context.Background())
if err != nil {
t.Fatalf("ошибка не ожидалсась: %v", err)
}
}
func ApiClient_TestGetDomains_Success(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
defer ts.Close()
client := &Client{
baseURL: ts.URL,
token: rand.Text(),
httpClient: ts.Client(),
}
_, err := client.GetDomains(context.Background())
if err != nil {
t.Fatal("ошибка не ожидалась")
}
}