From 31ede381e45c66fdd47d733839ce4f43013ceb33 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Mon, 18 Apr 2022 12:23:18 +0300 Subject: [PATCH] trim base URL in the constructor --- client.go | 2 +- client_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index d581733..321af9a 100644 --- a/client.go +++ b/client.go @@ -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}, } diff --git a/client_test.go b/client_test.go index 74631ca..57e20ac 100644 --- a/client_test.go +++ b/client_test.go @@ -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()