Trim base URL in the constructor

This commit is contained in:
Alex Lushpai 2022-04-18 12:57:35 +03:00 committed by GitHub
commit 9c7c641217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

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

View File

@ -68,6 +68,15 @@ func badurlclient() *Client {
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) {
c := client()