little bit tests
This commit is contained in:
parent
ed1d845933
commit
17cc791c86
1 changed files with 58 additions and 0 deletions
58
playtogo/client_test.go
Normal file
58
playtogo/client_test.go
Normal 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("ошибка не ожидалась")
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue