Skip to content

Commit

Permalink
moved mockvalue to util file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kshitij-Katiyar committed Dec 16, 2024
1 parent e4c1015 commit 617c349
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 4 additions & 0 deletions calendar/store/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions calendar/store/welcome_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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`)
Expand All @@ -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)
Expand Down

0 comments on commit 617c349

Please sign in to comment.