From d8debc67c72974811414a57bc02caa1557a64afc Mon Sep 17 00:00:00 2001 From: Pei-Ming Wu Date: Wed, 19 May 2021 22:32:11 +0800 Subject: [PATCH] test: add settings test (#11) --- api.go | 20 ------------------ api_internal_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 api_internal_test.go diff --git a/api.go b/api.go index 9449cbd..799f6ad 100644 --- a/api.go +++ b/api.go @@ -68,42 +68,22 @@ func New(authToken string, setters ...APISetting) *API { } func (c *API) Users() UsersInterface { - if c == nil { - return nil - } - return c.usersClient } func (c *API) Databases() DatabasesInterface { - if c == nil { - return nil - } - return c.databasesClient } func (c *API) Pages() PagesInterface { - if c == nil { - return nil - } - return c.pagesClient } func (c *API) Blocks() BlocksInterface { - if c == nil { - return nil - } - return c.blocksClient } func (c *API) Search(ctx context.Context, params SearchParameters) (*SearchResponse, error) { - if c == nil { - return nil, ErrUnknown - } - return c.searchClient.Search(ctx, params) } diff --git a/api_internal_test.go b/api_internal_test.go new file mode 100644 index 0000000..c073135 --- /dev/null +++ b/api_internal_test.go @@ -0,0 +1,48 @@ +package notion + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestWithUserAgent(t *testing.T) { + var settings apiSettings + + userAgent := "test-user-agent" + + WithUserAgent("test-user-agent")(&settings) + + assert.Equal(t, settings.userAgent, userAgent) +} + +func TestWithBaseURL(t *testing.T) { + var settings apiSettings + + baseURL := "https://example.com" + + WithBaseURL(baseURL)(&settings) + + assert.Equal(t, settings.baseURL, baseURL) +} + +func TestNotionVersion(t *testing.T) { + var settings apiSettings + + notionVersion := "2021-05-19" + + WithNotionVersion(notionVersion)(&settings) + + assert.Equal(t, settings.notionVersion, notionVersion) +} + +func TestHTTPClient(t *testing.T) { + var settings apiSettings + + httpClient := &http.Client{} + + WithHTTPClient(httpClient)(&settings) + + assert.Same(t, settings.httpClient, httpClient) +}