From 0a0de1f66962f761b9fc1b16b7661c22f9210948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B0?= Date: Mon, 12 Feb 2024 14:55:05 +0300 Subject: [PATCH] fix lint problem and test unmarshal message webhook --- v1/storage.go | 6 +++--- v1/storage_test.go | 5 +++-- v1/types_test.go | 29 +++++++++++++---------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/v1/storage.go b/v1/storage.go index eb98e61..55495ab 100644 --- a/v1/storage.go +++ b/v1/storage.go @@ -9,16 +9,16 @@ import ( const mgClientCacheTTL = time.Hour * 1 -var NegativeCapacity = errors.New("capacity cannot be less than 1") +var ErrNegativeCapacity = errors.New("capacity cannot be less than 1") type MGClientPool struct { cache *otter.CacheWithVariableTTL[string, *MgClient] } -// NewMGClientPool initializes the client cache +// NewMGClientPool initializes the client cache. func NewMGClientPool(capacity int) (*MGClientPool, error) { if capacity <= 0 { - return nil, NegativeCapacity + return nil, ErrNegativeCapacity } cache, _ := otter.MustBuilder[string, *MgClient](capacity).WithVariableTTL().Build() diff --git a/v1/storage_test.go b/v1/storage_test.go index 0f57f70..ca41c28 100644 --- a/v1/storage_test.go +++ b/v1/storage_test.go @@ -1,8 +1,9 @@ package v1 import ( - "github.com/stretchr/testify/suite" "testing" + + "github.com/stretchr/testify/suite" ) type StorageTest struct { @@ -26,5 +27,5 @@ func (t *StorageTest) Test_MGClientPool() { func (t *StorageTest) Test_NegativeCapacity() { _, err := NewMGClientPool(-1) - t.Assert().Equal(NegativeCapacity.Error(), err.Error()) + t.Assert().Equal(ErrNegativeCapacity.Error(), err.Error()) } diff --git a/v1/types_test.go b/v1/types_test.go index b767b37..5e7899a 100644 --- a/v1/types_test.go +++ b/v1/types_test.go @@ -306,22 +306,19 @@ func TestUnmarshalMessageWebhook(t *testing.T) { }, "template": { "code": "f87e678f_660b_461a_b60a_a6194e2e9094#thanks_for_order#ru", - "args": [ - "8061C", - "17400" - ], - "variables": { - "body": [ - "8061C", - "17400" - ], - "buttons": [ - [], - [ - "8061" - ] - ] - } + "variables": { + "body": { + "args": [ + "8061C", + "17400" + ] + }, + "buttons": [{ + "args": [ + "8061" + ] + }] + } }, "attachments": { "suggestions": [