trim base URL in the constructor

This commit is contained in:
Pavel 2022-04-18 12:23:18 +03:00
parent cd567755e7
commit 31ede381e4
2 changed files with 10 additions and 1 deletions

View File

@ -20,7 +20,7 @@ import (
// New initialize client. // New initialize client.
func New(url string, key string) *Client { func New(url string, key string) *Client {
return &Client{ return &Client{
URL: url, URL: strings.TrimRight(url, "/"),
Key: key, Key: key,
httpClient: &http.Client{Timeout: time.Minute}, httpClient: &http.Client{Timeout: time.Minute},
} }

View File

@ -68,6 +68,15 @@ func badurlclient() *Client {
return New(badURL, os.Getenv("RETAILCRM_KEY")) return New(badURL, os.Getenv("RETAILCRM_KEY"))
} }
func TestBaseURLTrimmed(t *testing.T) {
c1 := New("https://test.retailcrm.pro", "key")
c2 := New("https://test.retailcrm.pro/", "key")
c3 := New("https://test.retailcrm.pro////", "key")
assert.Equal(t, c1.URL, c2.URL)
assert.Equal(t, c1.URL, c3.URL)
}
func TestGetRequest(t *testing.T) { func TestGetRequest(t *testing.T) {
c := client() c := client()