diff --git a/test/integration/internal/mock/mockery/mock_repository_test.go b/test/integration/internal/mock/mockery/mock_repository_test.go deleted file mode 100644 index 1a90b9e..0000000 --- a/test/integration/internal/mock/mockery/mock_repository_test.go +++ /dev/null @@ -1,46 +0,0 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. - -package mockery - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" -) - -// repositoryMock is an autogenerated mock type for the repository type -type repositoryMock struct { - mock.Mock -} - -// Insert provides a mock function with given fields: ctx, val -func (_m *repositoryMock) Insert(ctx context.Context, val string) error { - ret := _m.Called(ctx, val) - - if len(ret) == 0 { - panic("no return value specified for Insert") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, val) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// newRepositoryMock creates a new instance of repositoryMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newRepositoryMock(t interface { - mock.TestingT - Cleanup(func()) -}) *repositoryMock { - mock := &repositoryMock{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/test/integration/internal/mock/mockery/mock_transactor_test.go b/test/integration/internal/mock/mockery/mock_transactor_test.go deleted file mode 100644 index dc955a1..0000000 --- a/test/integration/internal/mock/mockery/mock_transactor_test.go +++ /dev/null @@ -1,46 +0,0 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. - -package mockery - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" -) - -// transactorMock is an autogenerated mock type for the transactor type -type transactorMock struct { - mock.Mock -} - -// WithinTx provides a mock function with given fields: ctx, fn -func (_m *transactorMock) WithinTx(ctx context.Context, fn func(context.Context) error) error { - ret := _m.Called(ctx, fn) - - if len(ret) == 0 { - panic("no return value specified for WithinTx") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, func(context.Context) error) error); ok { - r0 = rf(ctx, fn) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// newTransactorMock creates a new instance of transactorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newTransactorMock(t interface { - mock.TestingT - Cleanup(func()) -}) *transactorMock { - mock := &transactorMock{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/test/integration/internal/mock/mockery/mockery_test.go b/test/integration/internal/mock/mockery/mockery_test.go index b16b6e4..5671754 100644 --- a/test/integration/internal/mock/mockery/mockery_test.go +++ b/test/integration/internal/mock/mockery/mockery_test.go @@ -19,7 +19,7 @@ const ( func Test_mockery(t *testing.T) { t.Run("assert_success", func(t *testing.T) { ctx := context.Background() - transactorMock := new(transactorMock) + transactorMock := new(mockTransactor) transactorMock.On(transactorMethodWithinTx, ctx, mock.MatchedBy(func(i any) bool { @@ -28,10 +28,10 @@ func Test_mockery(t *testing.T) { return assert.NoError(t, fn(ctx)) })).Return(nil) - repositoryMockA := new(repositoryMock) + repositoryMockA := new(mockRepository) repositoryMockA.On(repositoryMethodInsert, ctx, textValue).Return(nil) - repositoryMockB := new(repositoryMock) + repositoryMockB := new(mockRepository) repositoryMockB.On(repositoryMethodInsert, ctx, textValue).Return(nil) useCase := UseCase{ @@ -51,7 +51,7 @@ func Test_mockery(t *testing.T) { trsnsactorErr = fmt.Errorf("transactor_error") ) - transactorMock := new(transactorMock) + transactorMock := new(mockTransactor) transactorMock.On(transactorMethodWithinTx, ctx, mock.MatchedBy(func(i any) bool { @@ -61,10 +61,10 @@ func Test_mockery(t *testing.T) { }), ).Return(trsnsactorErr) - repositoryMockA := new(repositoryMock) + repositoryMockA := new(mockRepository) repositoryMockA.On(repositoryMethodInsert, ctx, textValue).Return(nil) - repositoryMockB := new(repositoryMock) + repositoryMockB := new(mockRepository) repositoryMockB.On(repositoryMethodInsert, ctx, textValue).Return(expError) useCase := UseCase{ diff --git a/test/integration/internal/mock/mockery/mocks_test.go b/test/integration/internal/mock/mockery/mocks_test.go new file mode 100644 index 0000000..46aa645 --- /dev/null +++ b/test/integration/internal/mock/mockery/mocks_test.go @@ -0,0 +1,83 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mockery + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// mockRepository is an autogenerated mock type for the repository type +type mockRepository struct { + mock.Mock +} + +// Insert provides a mock function with given fields: ctx, val +func (_m *mockRepository) Insert(ctx context.Context, val string) error { + ret := _m.Called(ctx, val) + + if len(ret) == 0 { + panic("no return value specified for Insert") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, val) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// newMockRepository creates a new instance of mockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *mockRepository { + mock := &mockRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// mockTransactor is an autogenerated mock type for the transactor type +type mockTransactor struct { + mock.Mock +} + +// WithinTx provides a mock function with given fields: ctx, fn +func (_m *mockTransactor) WithinTx(ctx context.Context, fn func(context.Context) error) error { + ret := _m.Called(ctx, fn) + + if len(ret) == 0 { + panic("no return value specified for WithinTx") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, func(context.Context) error) error); ok { + r0 = rf(ctx, fn) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// newMockTransactor creates a new instance of mockTransactor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockTransactor(t interface { + mock.TestingT + Cleanup(func()) +}) *mockTransactor { + mock := &mockTransactor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/test/integration/internal/mock/mockery/scripts.sh b/test/integration/internal/mock/mockery/scripts.sh new file mode 100755 index 0000000..7b1b0f0 --- /dev/null +++ b/test/integration/internal/mock/mockery/scripts.sh @@ -0,0 +1,46 @@ +# Script to merge mockery (v2) generated mocks. + + +mock_pattern=mock_*.go +mock_merge_file=mocks_test.go + +function update_mocks() { + path=${1:-.} + find ${path} -name "${mock_merge_file}" -delete + + echo "merge mocks: ${path}" + $(merge_mocks $path) + + echo "remove generated mocks by pattern: ${mock_pattern}" + $(rm_mocks $path) +} + +function merge_mocks() { + path=${1:-.} + patter=${path}/${mock_pattern} + result_file=${path}/${mock_merge_file} + + first=true + for f in ${patter}; do + if [ "${first}" = true ] ; then + (cat "${f}"; echo; echo;) >> ${result_file} + first=false + else + import_end_line=$(awk -v line=')' '$0 == line {print NR}' $f) + file_lines=$(wc -l < ${f}) + tail_lines=$((${file_lines} - ${import_end_line})) + (cat "${f}" | tail -n ${tail_lines}; echo; echo;) >> ${result_file} + fi + done + + exit 0 +} + +function rm_mocks() { + path=${1:-.} + find ${path} -name "${mock_pattern}" -delete + + exit 0 +} + +"$@" diff --git a/test/integration/internal/mock/mockery/usecase_test.go b/test/integration/internal/mock/mockery/usecase.go similarity index 72% rename from test/integration/internal/mock/mockery/usecase_test.go rename to test/integration/internal/mock/mockery/usecase.go index dd5e650..9846cbd 100644 --- a/test/integration/internal/mock/mockery/usecase_test.go +++ b/test/integration/internal/mock/mockery/usecase.go @@ -1,7 +1,7 @@ package mockery -//go:generate mockery --dir=. --name=repository --outpkg=mockery --output=. --filename=mock_repository_test.go --structname=repositoryMock -//go:generate mockery --dir=. --name=transactor --outpkg=mockery --output=. --filename=mock_transactor_test.go --structname=transactorMock +//go:generate mockery --inpackage --all --outpkg=mockery --dir=. --outpkg=profile --output=. +//go:generate sh ./scripts.sh update_mocks . //go:generate git add . import (