From 17cc791c865b59442e35aba13dedf9a151348734 Mon Sep 17 00:00:00 2001 From: Deerain <1deerain1@gmial.com> Date: Thu, 29 Oct 2026 01:42:44 +0300 Subject: [PATCH] little bit tests --- playtogo/client_test.go | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 playtogo/client_test.go diff --git a/playtogo/client_test.go b/playtogo/client_test.go new file mode 100644 index 0000000..5c51634 --- /dev/null +++ b/playtogo/client_test.go @@ -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("ошибка не ожидалась") + } + +}