From 617c349f36bd9db67941687535e7bb86fae6df4b Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Mon, 16 Dec 2024 16:51:03 +0530 Subject: [PATCH] moved mockvalue to util file --- calendar/store/test_util.go | 4 ++++ calendar/store/welcome_store_test.go | 11 ++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/calendar/store/test_util.go b/calendar/store/test_util.go index 97b21121..1fa8beae 100644 --- a/calendar/store/test_util.go +++ b/calendar/store/test_util.go @@ -12,6 +12,10 @@ import ( ) var MockString = mock.AnythingOfType("string") +var MockByteValue = mock.MatchedBy(func(arg interface{}) bool { + _, ok := arg.([]byte) + return ok +}) func GetMockSetup(t *testing.T) (*testutil.MockPluginAPI, Store, *mock_bot.MockLogger, *mock_bot.MockLogger, *mock_tracker.MockTracker) { ctrl := gomock.NewController(t) diff --git a/calendar/store/welcome_store_test.go b/calendar/store/welcome_store_test.go index 64a76e71..fc03f626 100644 --- a/calendar/store/welcome_store_test.go +++ b/calendar/store/welcome_store_test.go @@ -3,7 +3,6 @@ package store import ( "testing" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/mattermost/mattermost/server/public/model" @@ -65,10 +64,7 @@ func TestStoreUserWelcomePost(t *testing.T) { { name: "Error storing user welcome post", setup: func(mockAPI *testutil.MockPluginAPI) { - mockAPI.On("KVSet", MockString, mock.MatchedBy(func(arg interface{}) bool { - _, ok := arg.([]byte) - return ok - })).Return(&model.AppError{Message: "KVSet failed"}) + mockAPI.On("KVSet", MockString, MockByteValue).Return(&model.AppError{Message: "KVSet failed"}) }, assertions: func(t *testing.T, err error) { require.ErrorContainsf(t, err, "failed plugin KVSet (ttl: 0s)", `"mockMMUserID": KVSet failed`) @@ -77,10 +73,7 @@ func TestStoreUserWelcomePost(t *testing.T) { { name: "Success storing user welcome post", setup: func(mockAPI *testutil.MockPluginAPI) { - mockAPI.On("KVSet", MockString, mock.MatchedBy(func(arg interface{}) bool { - _, ok := arg.([]byte) - return ok - })).Return(nil) + mockAPI.On("KVSet", MockString, MockByteValue).Return(nil) }, assertions: func(t *testing.T, err error) { require.NoError(t, err)