diff --git a/go.mod b/go.mod index 814eb2d..ab8914b 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,11 @@ module github.com/xeeetu/gRPC go 1.22.5 require ( - github.com/Masterminds/squirrel v1.5.4 - github.com/brianvoe/gofakeit v3.18.0+incompatible + github.com/brianvoe/gofakeit/v7 v7.0.4 + github.com/gojuno/minimock/v3 v3.4.0 github.com/jackc/pgx/v4 v4.18.3 github.com/joho/godotenv v1.5.1 + github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 ) @@ -21,10 +22,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgtype v1.14.0 // indirect github.com/jackc/puddle v1.3.0 // indirect - github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect - github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.9.0 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect diff --git a/go.sum b/go.sum index e5577d7..8d724c8 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM= -github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= -github.com/brianvoe/gofakeit v3.18.0+incompatible h1:wDOmHc9DLG4nRjUVVaxA+CEglKOW72Y5+4WNxUIkjM8= -github.com/brianvoe/gofakeit v3.18.0+incompatible/go.mod h1:kfwdRA90vvNhPutZWfH7WPaDzUjz+CZFqG+rPkOjGOc= +github.com/brianvoe/gofakeit/v7 v7.0.4 h1:Mkxwz9jYg8Ad8NvT9HA27pCMZGFQo08MK6jD0QTKEww= +github.com/brianvoe/gofakeit/v7 v7.0.4/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= @@ -17,6 +15,8 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gojuno/minimock/v3 v3.4.0 h1:htPGQuFvmCaTygTnARPp5tSWZUZxOnu8A2RDVyl/LA8= +github.com/gojuno/minimock/v3 v3.4.0/go.mod h1:0PdkFMCugnywaAqwrdWMZMzHhSH3ZoXlMVHiRVdIrLk= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= @@ -74,14 +74,13 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= -github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= -github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= -github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -92,8 +91,9 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -114,8 +114,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= @@ -196,6 +194,8 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/api/note/tests/create_test.go b/internal/api/note/tests/create_test.go new file mode 100644 index 0000000..2f90fc4 --- /dev/null +++ b/internal/api/note/tests/create_test.go @@ -0,0 +1,100 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/api/note" + "github.com/xeeetu/gRPC/internal/service" + serviceMocks "github.com/xeeetu/gRPC/internal/service/mocks" + "github.com/xeeetu/gRPC/model" + desc "github.com/xeeetu/gRPC/pkg/note_v1" +) + +func TestCreate(t *testing.T) { + type noteServiceMockFunc func(mc *minimock.Controller) service.NoteService + + type args struct { + ctx context.Context + req *desc.CreateRequest + } + + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + id = gofakeit.Int64() + title = gofakeit.Name() + content = gofakeit.Name() + + serviceErr = fmt.Errorf("service error") + + req = &desc.CreateRequest{ + Info: &desc.NoteInfo{ + Title: title, + Content: content, + }, + } + + info = &model.NoteInfo{ + Title: title, + Content: content, + } + + res = &desc.CreateResponse{ + Id: id, + } + ) + + tests := []struct { + name string + args args + want *desc.CreateResponse + err error + noteServiceMockFunc noteServiceMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + req: req, + }, + want: res, + err: nil, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + mock.CreateMock.Expect(ctx, info).Return(id, nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + req: req, + }, + want: nil, + err: serviceErr, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + mock.CreateMock.Expect(ctx, info).Return(0, serviceErr) + return mock + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + noteServiceMock := tt.noteServiceMockFunc(mc) + api := note.NewImplementation(noteServiceMock) + + resHandler, err := api.Create(ctx, req) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/api/note/tests/delete_test.go b/internal/api/note/tests/delete_test.go new file mode 100644 index 0000000..4673a32 --- /dev/null +++ b/internal/api/note/tests/delete_test.go @@ -0,0 +1,91 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/api/note" + "github.com/xeeetu/gRPC/internal/service" + serviceMocks "github.com/xeeetu/gRPC/internal/service/mocks" + desc "github.com/xeeetu/gRPC/pkg/note_v1" + "google.golang.org/protobuf/types/known/emptypb" +) + +func TestDelete(t *testing.T) { + type noteServiceMockFunc func(mc *minimock.Controller) service.NoteService + + type args struct { + ctx context.Context + req *desc.DeleteRequest + } + + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + serviceErr = fmt.Errorf("service error") + + id = gofakeit.Int64() + + req = &desc.DeleteRequest{ + Id: id, + } + + res = &emptypb.Empty{} + ) + + tests := []struct { + name string + args args + want *emptypb.Empty + err error + noteServiceMockFunc noteServiceMockFunc + }{ + { + name: "success case", + args: args{ + ctx: context.Background(), + req: req, + }, + want: res, + err: nil, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + + mock.DeleteMock.Expect(ctx, id).Return(nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: context.Background(), + req: req, + }, + want: res, + err: serviceErr, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + + mock.DeleteMock.Expect(ctx, id).Return(serviceErr) + return mock + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mock := tt.noteServiceMockFunc(mc) + api := note.NewImplementation(mock) + + resHandler, err := api.Delete(tt.args.ctx, tt.args.req) + + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/api/note/tests/get_test.go b/internal/api/note/tests/get_test.go new file mode 100644 index 0000000..253a6c7 --- /dev/null +++ b/internal/api/note/tests/get_test.go @@ -0,0 +1,121 @@ +package tests + +import ( + "context" + "database/sql" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/api/note" + "github.com/xeeetu/gRPC/internal/service" + "github.com/xeeetu/gRPC/model" + + serviceMocks "github.com/xeeetu/gRPC/internal/service/mocks" + desc "github.com/xeeetu/gRPC/pkg/note_v1" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func TestGet(t *testing.T) { + type noteServiceMock func(mc *minimock.Controller) service.NoteService + + type args struct { + ctx context.Context + req *desc.GetRequest + } + + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + serviceErr = fmt.Errorf("service error") + + id = gofakeit.Int64() + title = gofakeit.Word() + content = gofakeit.Word() + createdAt = gofakeit.Date() + updatedAt = gofakeit.Date() + + req = &desc.GetRequest{ + Id: id, + } + + info = &desc.NoteInfo{ + Title: title, + Content: content, + } + + res = &desc.GetResponse{ + Note: &desc.Note{ + Id: id, + Info: info, + CreatedAt: timestamppb.New(createdAt), + UpdatedAt: timestamppb.New(updatedAt), + }, + } + + infoRes = model.NoteInfo{ + Title: title, + Content: content, + } + noteRes = &model.Note{ + ID: id, + Info: infoRes, + CreatedAt: createdAt, + UpdatedAt: sql.NullTime{ + Time: updatedAt, + Valid: true, + }, + } + ) + + tests := []struct { + name string + args args + want *desc.GetResponse + err error + noteServiceMockFunc noteServiceMock + }{ + { + name: "success case", + args: args{ + ctx: ctx, + req: req, + }, + want: res, + err: nil, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + mock.GetMock.Expect(ctx, id).Return(noteRes, nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + req: req, + }, + want: nil, + err: serviceErr, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + mock.GetMock.Expect(ctx, id).Return(nil, serviceErr) + return mock + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mock := tt.noteServiceMockFunc(mc) + api := note.NewImplementation(mock) + + resHandler, err := api.Get(ctx, req) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/api/note/tests/list_test.go b/internal/api/note/tests/list_test.go new file mode 100644 index 0000000..67dcafc --- /dev/null +++ b/internal/api/note/tests/list_test.go @@ -0,0 +1,96 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/api/note" + "github.com/xeeetu/gRPC/internal/service" + serviceMocks "github.com/xeeetu/gRPC/internal/service/mocks" + "github.com/xeeetu/gRPC/model" + desc "github.com/xeeetu/gRPC/pkg/note_v1" +) + +func TestList(t *testing.T) { + type noteServiceMockFunc func(mc *minimock.Controller) service.NoteService + + type args struct { + ctx context.Context + req *desc.ListRequest + } + + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + serviceErr = fmt.Errorf("service error") + + limit = int64(gofakeit.Number(1, 10)) + offset = int64(gofakeit.Number(1, 10)) + + req = &desc.ListRequest{ + Limit: limit, + Offset: offset, + } + + res = &desc.ListResponse{ + Notes: []*desc.Note{}, + } + + resModel = []*model.Note{} + ) + + tests := []struct { + name string + args args + want *desc.ListResponse + err error + noteServiceMockFunc noteServiceMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + req: req, + }, + want: res, + err: nil, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + + mock.ListMock.Expect(ctx, offset, limit).Return(resModel, nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + req: req, + }, + want: nil, + err: serviceErr, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + + mock.ListMock.Expect(ctx, offset, limit).Return(nil, serviceErr) + return mock + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mock := tt.noteServiceMockFunc(mc) + api := note.NewImplementation(mock) + + resHandler, err := api.List(tt.args.ctx, tt.args.req) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/api/note/tests/update_test.go b/internal/api/note/tests/update_test.go new file mode 100644 index 0000000..dc215a4 --- /dev/null +++ b/internal/api/note/tests/update_test.go @@ -0,0 +1,106 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/api/note" + "github.com/xeeetu/gRPC/internal/service" + serviceMocks "github.com/xeeetu/gRPC/internal/service/mocks" + "github.com/xeeetu/gRPC/model" + desc "github.com/xeeetu/gRPC/pkg/note_v1" + "google.golang.org/protobuf/types/known/emptypb" + "google.golang.org/protobuf/types/known/wrapperspb" +) + +func TestUpdate(t *testing.T) { + type noteServiceMockFunc func(mc *minimock.Controller) service.NoteService + + type args struct { + ctx context.Context + req *desc.UpdateRequest + } + + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + serviceErr = fmt.Errorf("service error") + + id = gofakeit.Int64() + title = gofakeit.Name() + content = gofakeit.Name() + + updateInfo = &desc.UpdateNoteInfo{ + Title: wrapperspb.String(title), + Content: wrapperspb.String(content), + } + + req = &desc.UpdateRequest{ + Id: id, + Info: updateInfo, + } + + modelUpdateInfo = &model.UpdateNoteInfo{ + Title: &title, + Content: &content, + } + + modelUpdate = &model.UpdateNote{ + ID: id, + Info: modelUpdateInfo, + } + ) + + tests := []struct { + name string + args args + want *emptypb.Empty + err error + noteServiceMockFunc noteServiceMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + req: req, + }, + want: &emptypb.Empty{}, + err: nil, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + mock.UpdateMock.Expect(ctx, modelUpdate).Return(nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + req: req, + }, + want: &emptypb.Empty{}, + err: serviceErr, + noteServiceMockFunc: func(mc *minimock.Controller) service.NoteService { + mock := serviceMocks.NewNoteServiceMock(mc) + mock.UpdateMock.Expect(ctx, modelUpdate).Return(serviceErr) + return mock + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mock := tt.noteServiceMockFunc(mc) + api := note.NewImplementation(mock) + + resHandler, err := api.Update(ctx, req) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/repository/generate.go b/internal/repository/generate.go new file mode 100644 index 0000000..4ec9fd6 --- /dev/null +++ b/internal/repository/generate.go @@ -0,0 +1,4 @@ +package repository + +//go:generate sh -c "rm -rf mocks && mkdir -p mocks" +//go:generate minimock -i NoteRepository -o ./mocks/ -s "_minimock.go" diff --git a/internal/repository/mocks/note_repository_minimock.go b/internal/repository/mocks/note_repository_minimock.go new file mode 100644 index 0000000..cc8e900 --- /dev/null +++ b/internal/repository/mocks/note_repository_minimock.go @@ -0,0 +1,1871 @@ +// Code generated by http://github.com/gojuno/minimock (v3.4.0). DO NOT EDIT. + +package mocks + +//go:generate minimock -i github.com/xeeetu/gRPC/internal/repository.NoteRepository -o note_repository_minimock.go -n NoteRepositoryMock -p mocks + +import ( + "context" + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" + "github.com/xeeetu/gRPC/model" +) + +// NoteRepositoryMock implements mm_repository.NoteRepository +type NoteRepositoryMock struct { + t minimock.Tester + finishOnce sync.Once + + funcCreate func(ctx context.Context, info *model.NoteInfo) (i1 int64, err error) + funcCreateOrigin string + inspectFuncCreate func(ctx context.Context, info *model.NoteInfo) + afterCreateCounter uint64 + beforeCreateCounter uint64 + CreateMock mNoteRepositoryMockCreate + + funcDelete func(ctx context.Context, id int64) (err error) + funcDeleteOrigin string + inspectFuncDelete func(ctx context.Context, id int64) + afterDeleteCounter uint64 + beforeDeleteCounter uint64 + DeleteMock mNoteRepositoryMockDelete + + funcGet func(ctx context.Context, id int64) (np1 *model.Note, err error) + funcGetOrigin string + inspectFuncGet func(ctx context.Context, id int64) + afterGetCounter uint64 + beforeGetCounter uint64 + GetMock mNoteRepositoryMockGet + + funcList func(ctx context.Context, offset int64, limit int64) (npa1 []*model.Note, err error) + funcListOrigin string + inspectFuncList func(ctx context.Context, offset int64, limit int64) + afterListCounter uint64 + beforeListCounter uint64 + ListMock mNoteRepositoryMockList + + funcUpdate func(ctx context.Context, info *model.UpdateNote) (err error) + funcUpdateOrigin string + inspectFuncUpdate func(ctx context.Context, info *model.UpdateNote) + afterUpdateCounter uint64 + beforeUpdateCounter uint64 + UpdateMock mNoteRepositoryMockUpdate +} + +// NewNoteRepositoryMock returns a mock for mm_repository.NoteRepository +func NewNoteRepositoryMock(t minimock.Tester) *NoteRepositoryMock { + m := &NoteRepositoryMock{t: t} + + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.CreateMock = mNoteRepositoryMockCreate{mock: m} + m.CreateMock.callArgs = []*NoteRepositoryMockCreateParams{} + + m.DeleteMock = mNoteRepositoryMockDelete{mock: m} + m.DeleteMock.callArgs = []*NoteRepositoryMockDeleteParams{} + + m.GetMock = mNoteRepositoryMockGet{mock: m} + m.GetMock.callArgs = []*NoteRepositoryMockGetParams{} + + m.ListMock = mNoteRepositoryMockList{mock: m} + m.ListMock.callArgs = []*NoteRepositoryMockListParams{} + + m.UpdateMock = mNoteRepositoryMockUpdate{mock: m} + m.UpdateMock.callArgs = []*NoteRepositoryMockUpdateParams{} + + t.Cleanup(m.MinimockFinish) + + return m +} + +type mNoteRepositoryMockCreate struct { + optional bool + mock *NoteRepositoryMock + defaultExpectation *NoteRepositoryMockCreateExpectation + expectations []*NoteRepositoryMockCreateExpectation + + callArgs []*NoteRepositoryMockCreateParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteRepositoryMockCreateExpectation specifies expectation struct of the NoteRepository.Create +type NoteRepositoryMockCreateExpectation struct { + mock *NoteRepositoryMock + params *NoteRepositoryMockCreateParams + paramPtrs *NoteRepositoryMockCreateParamPtrs + expectationOrigins NoteRepositoryMockCreateExpectationOrigins + results *NoteRepositoryMockCreateResults + returnOrigin string + Counter uint64 +} + +// NoteRepositoryMockCreateParams contains parameters of the NoteRepository.Create +type NoteRepositoryMockCreateParams struct { + ctx context.Context + info *model.NoteInfo +} + +// NoteRepositoryMockCreateParamPtrs contains pointers to parameters of the NoteRepository.Create +type NoteRepositoryMockCreateParamPtrs struct { + ctx *context.Context + info **model.NoteInfo +} + +// NoteRepositoryMockCreateResults contains results of the NoteRepository.Create +type NoteRepositoryMockCreateResults struct { + i1 int64 + err error +} + +// NoteRepositoryMockCreateOrigins contains origins of expectations of the NoteRepository.Create +type NoteRepositoryMockCreateExpectationOrigins struct { + origin string + originCtx string + originInfo string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmCreate *mNoteRepositoryMockCreate) Optional() *mNoteRepositoryMockCreate { + mmCreate.optional = true + return mmCreate +} + +// Expect sets up expected params for NoteRepository.Create +func (mmCreate *mNoteRepositoryMockCreate) Expect(ctx context.Context, info *model.NoteInfo) *mNoteRepositoryMockCreate { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteRepositoryMockCreateExpectation{} + } + + if mmCreate.defaultExpectation.paramPtrs != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by ExpectParams functions") + } + + mmCreate.defaultExpectation.params = &NoteRepositoryMockCreateParams{ctx, info} + mmCreate.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmCreate.expectations { + if minimock.Equal(e.params, mmCreate.defaultExpectation.params) { + mmCreate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreate.defaultExpectation.params) + } + } + + return mmCreate +} + +// ExpectCtxParam1 sets up expected param ctx for NoteRepository.Create +func (mmCreate *mNoteRepositoryMockCreate) ExpectCtxParam1(ctx context.Context) *mNoteRepositoryMockCreate { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteRepositoryMockCreateExpectation{} + } + + if mmCreate.defaultExpectation.params != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Expect") + } + + if mmCreate.defaultExpectation.paramPtrs == nil { + mmCreate.defaultExpectation.paramPtrs = &NoteRepositoryMockCreateParamPtrs{} + } + mmCreate.defaultExpectation.paramPtrs.ctx = &ctx + mmCreate.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmCreate +} + +// ExpectInfoParam2 sets up expected param info for NoteRepository.Create +func (mmCreate *mNoteRepositoryMockCreate) ExpectInfoParam2(info *model.NoteInfo) *mNoteRepositoryMockCreate { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteRepositoryMockCreateExpectation{} + } + + if mmCreate.defaultExpectation.params != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Expect") + } + + if mmCreate.defaultExpectation.paramPtrs == nil { + mmCreate.defaultExpectation.paramPtrs = &NoteRepositoryMockCreateParamPtrs{} + } + mmCreate.defaultExpectation.paramPtrs.info = &info + mmCreate.defaultExpectation.expectationOrigins.originInfo = minimock.CallerInfo(1) + + return mmCreate +} + +// Inspect accepts an inspector function that has same arguments as the NoteRepository.Create +func (mmCreate *mNoteRepositoryMockCreate) Inspect(f func(ctx context.Context, info *model.NoteInfo)) *mNoteRepositoryMockCreate { + if mmCreate.mock.inspectFuncCreate != nil { + mmCreate.mock.t.Fatalf("Inspect function is already set for NoteRepositoryMock.Create") + } + + mmCreate.mock.inspectFuncCreate = f + + return mmCreate +} + +// Return sets up results that will be returned by NoteRepository.Create +func (mmCreate *mNoteRepositoryMockCreate) Return(i1 int64, err error) *NoteRepositoryMock { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteRepositoryMockCreateExpectation{mock: mmCreate.mock} + } + mmCreate.defaultExpectation.results = &NoteRepositoryMockCreateResults{i1, err} + mmCreate.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmCreate.mock +} + +// Set uses given function f to mock the NoteRepository.Create method +func (mmCreate *mNoteRepositoryMockCreate) Set(f func(ctx context.Context, info *model.NoteInfo) (i1 int64, err error)) *NoteRepositoryMock { + if mmCreate.defaultExpectation != nil { + mmCreate.mock.t.Fatalf("Default expectation is already set for the NoteRepository.Create method") + } + + if len(mmCreate.expectations) > 0 { + mmCreate.mock.t.Fatalf("Some expectations are already set for the NoteRepository.Create method") + } + + mmCreate.mock.funcCreate = f + mmCreate.mock.funcCreateOrigin = minimock.CallerInfo(1) + return mmCreate.mock +} + +// When sets expectation for the NoteRepository.Create which will trigger the result defined by the following +// Then helper +func (mmCreate *mNoteRepositoryMockCreate) When(ctx context.Context, info *model.NoteInfo) *NoteRepositoryMockCreateExpectation { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteRepositoryMock.Create mock is already set by Set") + } + + expectation := &NoteRepositoryMockCreateExpectation{ + mock: mmCreate.mock, + params: &NoteRepositoryMockCreateParams{ctx, info}, + expectationOrigins: NoteRepositoryMockCreateExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmCreate.expectations = append(mmCreate.expectations, expectation) + return expectation +} + +// Then sets up NoteRepository.Create return parameters for the expectation previously defined by the When method +func (e *NoteRepositoryMockCreateExpectation) Then(i1 int64, err error) *NoteRepositoryMock { + e.results = &NoteRepositoryMockCreateResults{i1, err} + return e.mock +} + +// Times sets number of times NoteRepository.Create should be invoked +func (mmCreate *mNoteRepositoryMockCreate) Times(n uint64) *mNoteRepositoryMockCreate { + if n == 0 { + mmCreate.mock.t.Fatalf("Times of NoteRepositoryMock.Create mock can not be zero") + } + mm_atomic.StoreUint64(&mmCreate.expectedInvocations, n) + mmCreate.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmCreate +} + +func (mmCreate *mNoteRepositoryMockCreate) invocationsDone() bool { + if len(mmCreate.expectations) == 0 && mmCreate.defaultExpectation == nil && mmCreate.mock.funcCreate == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmCreate.mock.afterCreateCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmCreate.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Create implements mm_repository.NoteRepository +func (mmCreate *NoteRepositoryMock) Create(ctx context.Context, info *model.NoteInfo) (i1 int64, err error) { + mm_atomic.AddUint64(&mmCreate.beforeCreateCounter, 1) + defer mm_atomic.AddUint64(&mmCreate.afterCreateCounter, 1) + + mmCreate.t.Helper() + + if mmCreate.inspectFuncCreate != nil { + mmCreate.inspectFuncCreate(ctx, info) + } + + mm_params := NoteRepositoryMockCreateParams{ctx, info} + + // Record call args + mmCreate.CreateMock.mutex.Lock() + mmCreate.CreateMock.callArgs = append(mmCreate.CreateMock.callArgs, &mm_params) + mmCreate.CreateMock.mutex.Unlock() + + for _, e := range mmCreate.CreateMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.i1, e.results.err + } + } + + if mmCreate.CreateMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmCreate.CreateMock.defaultExpectation.Counter, 1) + mm_want := mmCreate.CreateMock.defaultExpectation.params + mm_want_ptrs := mmCreate.CreateMock.defaultExpectation.paramPtrs + + mm_got := NoteRepositoryMockCreateParams{ctx, info} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmCreate.t.Errorf("NoteRepositoryMock.Create got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmCreate.CreateMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.info != nil && !minimock.Equal(*mm_want_ptrs.info, mm_got.info) { + mmCreate.t.Errorf("NoteRepositoryMock.Create got unexpected parameter info, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmCreate.CreateMock.defaultExpectation.expectationOrigins.originInfo, *mm_want_ptrs.info, mm_got.info, minimock.Diff(*mm_want_ptrs.info, mm_got.info)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmCreate.t.Errorf("NoteRepositoryMock.Create got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmCreate.CreateMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmCreate.CreateMock.defaultExpectation.results + if mm_results == nil { + mmCreate.t.Fatal("No results are set for the NoteRepositoryMock.Create") + } + return (*mm_results).i1, (*mm_results).err + } + if mmCreate.funcCreate != nil { + return mmCreate.funcCreate(ctx, info) + } + mmCreate.t.Fatalf("Unexpected call to NoteRepositoryMock.Create. %v %v", ctx, info) + return +} + +// CreateAfterCounter returns a count of finished NoteRepositoryMock.Create invocations +func (mmCreate *NoteRepositoryMock) CreateAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreate.afterCreateCounter) +} + +// CreateBeforeCounter returns a count of NoteRepositoryMock.Create invocations +func (mmCreate *NoteRepositoryMock) CreateBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreate.beforeCreateCounter) +} + +// Calls returns a list of arguments used in each call to NoteRepositoryMock.Create. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmCreate *mNoteRepositoryMockCreate) Calls() []*NoteRepositoryMockCreateParams { + mmCreate.mutex.RLock() + + argCopy := make([]*NoteRepositoryMockCreateParams, len(mmCreate.callArgs)) + copy(argCopy, mmCreate.callArgs) + + mmCreate.mutex.RUnlock() + + return argCopy +} + +// MinimockCreateDone returns true if the count of the Create invocations corresponds +// the number of defined expectations +func (m *NoteRepositoryMock) MinimockCreateDone() bool { + if m.CreateMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.CreateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.CreateMock.invocationsDone() +} + +// MinimockCreateInspect logs each unmet expectation +func (m *NoteRepositoryMock) MinimockCreateInspect() { + for _, e := range m.CreateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Create at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterCreateCounter := mm_atomic.LoadUint64(&m.afterCreateCounter) + // if default expectation was set then invocations count should be greater than zero + if m.CreateMock.defaultExpectation != nil && afterCreateCounter < 1 { + if m.CreateMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteRepositoryMock.Create at\n%s", m.CreateMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteRepositoryMock.Create at\n%s with params: %#v", m.CreateMock.defaultExpectation.expectationOrigins.origin, *m.CreateMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcCreate != nil && afterCreateCounter < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Create at\n%s", m.funcCreateOrigin) + } + + if !m.CreateMock.invocationsDone() && afterCreateCounter > 0 { + m.t.Errorf("Expected %d calls to NoteRepositoryMock.Create at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.CreateMock.expectedInvocations), m.CreateMock.expectedInvocationsOrigin, afterCreateCounter) + } +} + +type mNoteRepositoryMockDelete struct { + optional bool + mock *NoteRepositoryMock + defaultExpectation *NoteRepositoryMockDeleteExpectation + expectations []*NoteRepositoryMockDeleteExpectation + + callArgs []*NoteRepositoryMockDeleteParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteRepositoryMockDeleteExpectation specifies expectation struct of the NoteRepository.Delete +type NoteRepositoryMockDeleteExpectation struct { + mock *NoteRepositoryMock + params *NoteRepositoryMockDeleteParams + paramPtrs *NoteRepositoryMockDeleteParamPtrs + expectationOrigins NoteRepositoryMockDeleteExpectationOrigins + results *NoteRepositoryMockDeleteResults + returnOrigin string + Counter uint64 +} + +// NoteRepositoryMockDeleteParams contains parameters of the NoteRepository.Delete +type NoteRepositoryMockDeleteParams struct { + ctx context.Context + id int64 +} + +// NoteRepositoryMockDeleteParamPtrs contains pointers to parameters of the NoteRepository.Delete +type NoteRepositoryMockDeleteParamPtrs struct { + ctx *context.Context + id *int64 +} + +// NoteRepositoryMockDeleteResults contains results of the NoteRepository.Delete +type NoteRepositoryMockDeleteResults struct { + err error +} + +// NoteRepositoryMockDeleteOrigins contains origins of expectations of the NoteRepository.Delete +type NoteRepositoryMockDeleteExpectationOrigins struct { + origin string + originCtx string + originId string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmDelete *mNoteRepositoryMockDelete) Optional() *mNoteRepositoryMockDelete { + mmDelete.optional = true + return mmDelete +} + +// Expect sets up expected params for NoteRepository.Delete +func (mmDelete *mNoteRepositoryMockDelete) Expect(ctx context.Context, id int64) *mNoteRepositoryMockDelete { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteRepositoryMockDeleteExpectation{} + } + + if mmDelete.defaultExpectation.paramPtrs != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by ExpectParams functions") + } + + mmDelete.defaultExpectation.params = &NoteRepositoryMockDeleteParams{ctx, id} + mmDelete.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmDelete.expectations { + if minimock.Equal(e.params, mmDelete.defaultExpectation.params) { + mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params) + } + } + + return mmDelete +} + +// ExpectCtxParam1 sets up expected param ctx for NoteRepository.Delete +func (mmDelete *mNoteRepositoryMockDelete) ExpectCtxParam1(ctx context.Context) *mNoteRepositoryMockDelete { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteRepositoryMockDeleteExpectation{} + } + + if mmDelete.defaultExpectation.params != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Expect") + } + + if mmDelete.defaultExpectation.paramPtrs == nil { + mmDelete.defaultExpectation.paramPtrs = &NoteRepositoryMockDeleteParamPtrs{} + } + mmDelete.defaultExpectation.paramPtrs.ctx = &ctx + mmDelete.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmDelete +} + +// ExpectIdParam2 sets up expected param id for NoteRepository.Delete +func (mmDelete *mNoteRepositoryMockDelete) ExpectIdParam2(id int64) *mNoteRepositoryMockDelete { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteRepositoryMockDeleteExpectation{} + } + + if mmDelete.defaultExpectation.params != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Expect") + } + + if mmDelete.defaultExpectation.paramPtrs == nil { + mmDelete.defaultExpectation.paramPtrs = &NoteRepositoryMockDeleteParamPtrs{} + } + mmDelete.defaultExpectation.paramPtrs.id = &id + mmDelete.defaultExpectation.expectationOrigins.originId = minimock.CallerInfo(1) + + return mmDelete +} + +// Inspect accepts an inspector function that has same arguments as the NoteRepository.Delete +func (mmDelete *mNoteRepositoryMockDelete) Inspect(f func(ctx context.Context, id int64)) *mNoteRepositoryMockDelete { + if mmDelete.mock.inspectFuncDelete != nil { + mmDelete.mock.t.Fatalf("Inspect function is already set for NoteRepositoryMock.Delete") + } + + mmDelete.mock.inspectFuncDelete = f + + return mmDelete +} + +// Return sets up results that will be returned by NoteRepository.Delete +func (mmDelete *mNoteRepositoryMockDelete) Return(err error) *NoteRepositoryMock { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteRepositoryMockDeleteExpectation{mock: mmDelete.mock} + } + mmDelete.defaultExpectation.results = &NoteRepositoryMockDeleteResults{err} + mmDelete.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmDelete.mock +} + +// Set uses given function f to mock the NoteRepository.Delete method +func (mmDelete *mNoteRepositoryMockDelete) Set(f func(ctx context.Context, id int64) (err error)) *NoteRepositoryMock { + if mmDelete.defaultExpectation != nil { + mmDelete.mock.t.Fatalf("Default expectation is already set for the NoteRepository.Delete method") + } + + if len(mmDelete.expectations) > 0 { + mmDelete.mock.t.Fatalf("Some expectations are already set for the NoteRepository.Delete method") + } + + mmDelete.mock.funcDelete = f + mmDelete.mock.funcDeleteOrigin = minimock.CallerInfo(1) + return mmDelete.mock +} + +// When sets expectation for the NoteRepository.Delete which will trigger the result defined by the following +// Then helper +func (mmDelete *mNoteRepositoryMockDelete) When(ctx context.Context, id int64) *NoteRepositoryMockDeleteExpectation { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteRepositoryMock.Delete mock is already set by Set") + } + + expectation := &NoteRepositoryMockDeleteExpectation{ + mock: mmDelete.mock, + params: &NoteRepositoryMockDeleteParams{ctx, id}, + expectationOrigins: NoteRepositoryMockDeleteExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmDelete.expectations = append(mmDelete.expectations, expectation) + return expectation +} + +// Then sets up NoteRepository.Delete return parameters for the expectation previously defined by the When method +func (e *NoteRepositoryMockDeleteExpectation) Then(err error) *NoteRepositoryMock { + e.results = &NoteRepositoryMockDeleteResults{err} + return e.mock +} + +// Times sets number of times NoteRepository.Delete should be invoked +func (mmDelete *mNoteRepositoryMockDelete) Times(n uint64) *mNoteRepositoryMockDelete { + if n == 0 { + mmDelete.mock.t.Fatalf("Times of NoteRepositoryMock.Delete mock can not be zero") + } + mm_atomic.StoreUint64(&mmDelete.expectedInvocations, n) + mmDelete.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmDelete +} + +func (mmDelete *mNoteRepositoryMockDelete) invocationsDone() bool { + if len(mmDelete.expectations) == 0 && mmDelete.defaultExpectation == nil && mmDelete.mock.funcDelete == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmDelete.mock.afterDeleteCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmDelete.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Delete implements mm_repository.NoteRepository +func (mmDelete *NoteRepositoryMock) Delete(ctx context.Context, id int64) (err error) { + mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1) + defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1) + + mmDelete.t.Helper() + + if mmDelete.inspectFuncDelete != nil { + mmDelete.inspectFuncDelete(ctx, id) + } + + mm_params := NoteRepositoryMockDeleteParams{ctx, id} + + // Record call args + mmDelete.DeleteMock.mutex.Lock() + mmDelete.DeleteMock.callArgs = append(mmDelete.DeleteMock.callArgs, &mm_params) + mmDelete.DeleteMock.mutex.Unlock() + + for _, e := range mmDelete.DeleteMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmDelete.DeleteMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmDelete.DeleteMock.defaultExpectation.Counter, 1) + mm_want := mmDelete.DeleteMock.defaultExpectation.params + mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs + + mm_got := NoteRepositoryMockDeleteParams{ctx, id} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmDelete.t.Errorf("NoteRepositoryMock.Delete got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmDelete.DeleteMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) { + mmDelete.t.Errorf("NoteRepositoryMock.Delete got unexpected parameter id, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmDelete.DeleteMock.defaultExpectation.expectationOrigins.originId, *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmDelete.t.Errorf("NoteRepositoryMock.Delete got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmDelete.DeleteMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmDelete.DeleteMock.defaultExpectation.results + if mm_results == nil { + mmDelete.t.Fatal("No results are set for the NoteRepositoryMock.Delete") + } + return (*mm_results).err + } + if mmDelete.funcDelete != nil { + return mmDelete.funcDelete(ctx, id) + } + mmDelete.t.Fatalf("Unexpected call to NoteRepositoryMock.Delete. %v %v", ctx, id) + return +} + +// DeleteAfterCounter returns a count of finished NoteRepositoryMock.Delete invocations +func (mmDelete *NoteRepositoryMock) DeleteAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmDelete.afterDeleteCounter) +} + +// DeleteBeforeCounter returns a count of NoteRepositoryMock.Delete invocations +func (mmDelete *NoteRepositoryMock) DeleteBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmDelete.beforeDeleteCounter) +} + +// Calls returns a list of arguments used in each call to NoteRepositoryMock.Delete. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmDelete *mNoteRepositoryMockDelete) Calls() []*NoteRepositoryMockDeleteParams { + mmDelete.mutex.RLock() + + argCopy := make([]*NoteRepositoryMockDeleteParams, len(mmDelete.callArgs)) + copy(argCopy, mmDelete.callArgs) + + mmDelete.mutex.RUnlock() + + return argCopy +} + +// MinimockDeleteDone returns true if the count of the Delete invocations corresponds +// the number of defined expectations +func (m *NoteRepositoryMock) MinimockDeleteDone() bool { + if m.DeleteMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.DeleteMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.DeleteMock.invocationsDone() +} + +// MinimockDeleteInspect logs each unmet expectation +func (m *NoteRepositoryMock) MinimockDeleteInspect() { + for _, e := range m.DeleteMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Delete at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterDeleteCounter := mm_atomic.LoadUint64(&m.afterDeleteCounter) + // if default expectation was set then invocations count should be greater than zero + if m.DeleteMock.defaultExpectation != nil && afterDeleteCounter < 1 { + if m.DeleteMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteRepositoryMock.Delete at\n%s", m.DeleteMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteRepositoryMock.Delete at\n%s with params: %#v", m.DeleteMock.defaultExpectation.expectationOrigins.origin, *m.DeleteMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcDelete != nil && afterDeleteCounter < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Delete at\n%s", m.funcDeleteOrigin) + } + + if !m.DeleteMock.invocationsDone() && afterDeleteCounter > 0 { + m.t.Errorf("Expected %d calls to NoteRepositoryMock.Delete at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.DeleteMock.expectedInvocations), m.DeleteMock.expectedInvocationsOrigin, afterDeleteCounter) + } +} + +type mNoteRepositoryMockGet struct { + optional bool + mock *NoteRepositoryMock + defaultExpectation *NoteRepositoryMockGetExpectation + expectations []*NoteRepositoryMockGetExpectation + + callArgs []*NoteRepositoryMockGetParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteRepositoryMockGetExpectation specifies expectation struct of the NoteRepository.Get +type NoteRepositoryMockGetExpectation struct { + mock *NoteRepositoryMock + params *NoteRepositoryMockGetParams + paramPtrs *NoteRepositoryMockGetParamPtrs + expectationOrigins NoteRepositoryMockGetExpectationOrigins + results *NoteRepositoryMockGetResults + returnOrigin string + Counter uint64 +} + +// NoteRepositoryMockGetParams contains parameters of the NoteRepository.Get +type NoteRepositoryMockGetParams struct { + ctx context.Context + id int64 +} + +// NoteRepositoryMockGetParamPtrs contains pointers to parameters of the NoteRepository.Get +type NoteRepositoryMockGetParamPtrs struct { + ctx *context.Context + id *int64 +} + +// NoteRepositoryMockGetResults contains results of the NoteRepository.Get +type NoteRepositoryMockGetResults struct { + np1 *model.Note + err error +} + +// NoteRepositoryMockGetOrigins contains origins of expectations of the NoteRepository.Get +type NoteRepositoryMockGetExpectationOrigins struct { + origin string + originCtx string + originId string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmGet *mNoteRepositoryMockGet) Optional() *mNoteRepositoryMockGet { + mmGet.optional = true + return mmGet +} + +// Expect sets up expected params for NoteRepository.Get +func (mmGet *mNoteRepositoryMockGet) Expect(ctx context.Context, id int64) *mNoteRepositoryMockGet { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteRepositoryMockGetExpectation{} + } + + if mmGet.defaultExpectation.paramPtrs != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by ExpectParams functions") + } + + mmGet.defaultExpectation.params = &NoteRepositoryMockGetParams{ctx, id} + mmGet.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmGet.expectations { + if minimock.Equal(e.params, mmGet.defaultExpectation.params) { + mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params) + } + } + + return mmGet +} + +// ExpectCtxParam1 sets up expected param ctx for NoteRepository.Get +func (mmGet *mNoteRepositoryMockGet) ExpectCtxParam1(ctx context.Context) *mNoteRepositoryMockGet { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteRepositoryMockGetExpectation{} + } + + if mmGet.defaultExpectation.params != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Expect") + } + + if mmGet.defaultExpectation.paramPtrs == nil { + mmGet.defaultExpectation.paramPtrs = &NoteRepositoryMockGetParamPtrs{} + } + mmGet.defaultExpectation.paramPtrs.ctx = &ctx + mmGet.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmGet +} + +// ExpectIdParam2 sets up expected param id for NoteRepository.Get +func (mmGet *mNoteRepositoryMockGet) ExpectIdParam2(id int64) *mNoteRepositoryMockGet { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteRepositoryMockGetExpectation{} + } + + if mmGet.defaultExpectation.params != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Expect") + } + + if mmGet.defaultExpectation.paramPtrs == nil { + mmGet.defaultExpectation.paramPtrs = &NoteRepositoryMockGetParamPtrs{} + } + mmGet.defaultExpectation.paramPtrs.id = &id + mmGet.defaultExpectation.expectationOrigins.originId = minimock.CallerInfo(1) + + return mmGet +} + +// Inspect accepts an inspector function that has same arguments as the NoteRepository.Get +func (mmGet *mNoteRepositoryMockGet) Inspect(f func(ctx context.Context, id int64)) *mNoteRepositoryMockGet { + if mmGet.mock.inspectFuncGet != nil { + mmGet.mock.t.Fatalf("Inspect function is already set for NoteRepositoryMock.Get") + } + + mmGet.mock.inspectFuncGet = f + + return mmGet +} + +// Return sets up results that will be returned by NoteRepository.Get +func (mmGet *mNoteRepositoryMockGet) Return(np1 *model.Note, err error) *NoteRepositoryMock { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteRepositoryMockGetExpectation{mock: mmGet.mock} + } + mmGet.defaultExpectation.results = &NoteRepositoryMockGetResults{np1, err} + mmGet.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmGet.mock +} + +// Set uses given function f to mock the NoteRepository.Get method +func (mmGet *mNoteRepositoryMockGet) Set(f func(ctx context.Context, id int64) (np1 *model.Note, err error)) *NoteRepositoryMock { + if mmGet.defaultExpectation != nil { + mmGet.mock.t.Fatalf("Default expectation is already set for the NoteRepository.Get method") + } + + if len(mmGet.expectations) > 0 { + mmGet.mock.t.Fatalf("Some expectations are already set for the NoteRepository.Get method") + } + + mmGet.mock.funcGet = f + mmGet.mock.funcGetOrigin = minimock.CallerInfo(1) + return mmGet.mock +} + +// When sets expectation for the NoteRepository.Get which will trigger the result defined by the following +// Then helper +func (mmGet *mNoteRepositoryMockGet) When(ctx context.Context, id int64) *NoteRepositoryMockGetExpectation { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteRepositoryMock.Get mock is already set by Set") + } + + expectation := &NoteRepositoryMockGetExpectation{ + mock: mmGet.mock, + params: &NoteRepositoryMockGetParams{ctx, id}, + expectationOrigins: NoteRepositoryMockGetExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmGet.expectations = append(mmGet.expectations, expectation) + return expectation +} + +// Then sets up NoteRepository.Get return parameters for the expectation previously defined by the When method +func (e *NoteRepositoryMockGetExpectation) Then(np1 *model.Note, err error) *NoteRepositoryMock { + e.results = &NoteRepositoryMockGetResults{np1, err} + return e.mock +} + +// Times sets number of times NoteRepository.Get should be invoked +func (mmGet *mNoteRepositoryMockGet) Times(n uint64) *mNoteRepositoryMockGet { + if n == 0 { + mmGet.mock.t.Fatalf("Times of NoteRepositoryMock.Get mock can not be zero") + } + mm_atomic.StoreUint64(&mmGet.expectedInvocations, n) + mmGet.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmGet +} + +func (mmGet *mNoteRepositoryMockGet) invocationsDone() bool { + if len(mmGet.expectations) == 0 && mmGet.defaultExpectation == nil && mmGet.mock.funcGet == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGet.mock.afterGetCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGet.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Get implements mm_repository.NoteRepository +func (mmGet *NoteRepositoryMock) Get(ctx context.Context, id int64) (np1 *model.Note, err error) { + mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1) + defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1) + + mmGet.t.Helper() + + if mmGet.inspectFuncGet != nil { + mmGet.inspectFuncGet(ctx, id) + } + + mm_params := NoteRepositoryMockGetParams{ctx, id} + + // Record call args + mmGet.GetMock.mutex.Lock() + mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, &mm_params) + mmGet.GetMock.mutex.Unlock() + + for _, e := range mmGet.GetMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.np1, e.results.err + } + } + + if mmGet.GetMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1) + mm_want := mmGet.GetMock.defaultExpectation.params + mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs + + mm_got := NoteRepositoryMockGetParams{ctx, id} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGet.t.Errorf("NoteRepositoryMock.Get got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmGet.GetMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) { + mmGet.t.Errorf("NoteRepositoryMock.Get got unexpected parameter id, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmGet.GetMock.defaultExpectation.expectationOrigins.originId, *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGet.t.Errorf("NoteRepositoryMock.Get got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmGet.GetMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGet.GetMock.defaultExpectation.results + if mm_results == nil { + mmGet.t.Fatal("No results are set for the NoteRepositoryMock.Get") + } + return (*mm_results).np1, (*mm_results).err + } + if mmGet.funcGet != nil { + return mmGet.funcGet(ctx, id) + } + mmGet.t.Fatalf("Unexpected call to NoteRepositoryMock.Get. %v %v", ctx, id) + return +} + +// GetAfterCounter returns a count of finished NoteRepositoryMock.Get invocations +func (mmGet *NoteRepositoryMock) GetAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGet.afterGetCounter) +} + +// GetBeforeCounter returns a count of NoteRepositoryMock.Get invocations +func (mmGet *NoteRepositoryMock) GetBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGet.beforeGetCounter) +} + +// Calls returns a list of arguments used in each call to NoteRepositoryMock.Get. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGet *mNoteRepositoryMockGet) Calls() []*NoteRepositoryMockGetParams { + mmGet.mutex.RLock() + + argCopy := make([]*NoteRepositoryMockGetParams, len(mmGet.callArgs)) + copy(argCopy, mmGet.callArgs) + + mmGet.mutex.RUnlock() + + return argCopy +} + +// MinimockGetDone returns true if the count of the Get invocations corresponds +// the number of defined expectations +func (m *NoteRepositoryMock) MinimockGetDone() bool { + if m.GetMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.GetMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetMock.invocationsDone() +} + +// MinimockGetInspect logs each unmet expectation +func (m *NoteRepositoryMock) MinimockGetInspect() { + for _, e := range m.GetMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Get at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterGetCounter := mm_atomic.LoadUint64(&m.afterGetCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetMock.defaultExpectation != nil && afterGetCounter < 1 { + if m.GetMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteRepositoryMock.Get at\n%s", m.GetMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteRepositoryMock.Get at\n%s with params: %#v", m.GetMock.defaultExpectation.expectationOrigins.origin, *m.GetMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGet != nil && afterGetCounter < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Get at\n%s", m.funcGetOrigin) + } + + if !m.GetMock.invocationsDone() && afterGetCounter > 0 { + m.t.Errorf("Expected %d calls to NoteRepositoryMock.Get at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.GetMock.expectedInvocations), m.GetMock.expectedInvocationsOrigin, afterGetCounter) + } +} + +type mNoteRepositoryMockList struct { + optional bool + mock *NoteRepositoryMock + defaultExpectation *NoteRepositoryMockListExpectation + expectations []*NoteRepositoryMockListExpectation + + callArgs []*NoteRepositoryMockListParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteRepositoryMockListExpectation specifies expectation struct of the NoteRepository.List +type NoteRepositoryMockListExpectation struct { + mock *NoteRepositoryMock + params *NoteRepositoryMockListParams + paramPtrs *NoteRepositoryMockListParamPtrs + expectationOrigins NoteRepositoryMockListExpectationOrigins + results *NoteRepositoryMockListResults + returnOrigin string + Counter uint64 +} + +// NoteRepositoryMockListParams contains parameters of the NoteRepository.List +type NoteRepositoryMockListParams struct { + ctx context.Context + offset int64 + limit int64 +} + +// NoteRepositoryMockListParamPtrs contains pointers to parameters of the NoteRepository.List +type NoteRepositoryMockListParamPtrs struct { + ctx *context.Context + offset *int64 + limit *int64 +} + +// NoteRepositoryMockListResults contains results of the NoteRepository.List +type NoteRepositoryMockListResults struct { + npa1 []*model.Note + err error +} + +// NoteRepositoryMockListOrigins contains origins of expectations of the NoteRepository.List +type NoteRepositoryMockListExpectationOrigins struct { + origin string + originCtx string + originOffset string + originLimit string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmList *mNoteRepositoryMockList) Optional() *mNoteRepositoryMockList { + mmList.optional = true + return mmList +} + +// Expect sets up expected params for NoteRepository.List +func (mmList *mNoteRepositoryMockList) Expect(ctx context.Context, offset int64, limit int64) *mNoteRepositoryMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteRepositoryMockListExpectation{} + } + + if mmList.defaultExpectation.paramPtrs != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by ExpectParams functions") + } + + mmList.defaultExpectation.params = &NoteRepositoryMockListParams{ctx, offset, limit} + mmList.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmList.expectations { + if minimock.Equal(e.params, mmList.defaultExpectation.params) { + mmList.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmList.defaultExpectation.params) + } + } + + return mmList +} + +// ExpectCtxParam1 sets up expected param ctx for NoteRepository.List +func (mmList *mNoteRepositoryMockList) ExpectCtxParam1(ctx context.Context) *mNoteRepositoryMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteRepositoryMockListExpectation{} + } + + if mmList.defaultExpectation.params != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Expect") + } + + if mmList.defaultExpectation.paramPtrs == nil { + mmList.defaultExpectation.paramPtrs = &NoteRepositoryMockListParamPtrs{} + } + mmList.defaultExpectation.paramPtrs.ctx = &ctx + mmList.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmList +} + +// ExpectOffsetParam2 sets up expected param offset for NoteRepository.List +func (mmList *mNoteRepositoryMockList) ExpectOffsetParam2(offset int64) *mNoteRepositoryMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteRepositoryMockListExpectation{} + } + + if mmList.defaultExpectation.params != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Expect") + } + + if mmList.defaultExpectation.paramPtrs == nil { + mmList.defaultExpectation.paramPtrs = &NoteRepositoryMockListParamPtrs{} + } + mmList.defaultExpectation.paramPtrs.offset = &offset + mmList.defaultExpectation.expectationOrigins.originOffset = minimock.CallerInfo(1) + + return mmList +} + +// ExpectLimitParam3 sets up expected param limit for NoteRepository.List +func (mmList *mNoteRepositoryMockList) ExpectLimitParam3(limit int64) *mNoteRepositoryMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteRepositoryMockListExpectation{} + } + + if mmList.defaultExpectation.params != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Expect") + } + + if mmList.defaultExpectation.paramPtrs == nil { + mmList.defaultExpectation.paramPtrs = &NoteRepositoryMockListParamPtrs{} + } + mmList.defaultExpectation.paramPtrs.limit = &limit + mmList.defaultExpectation.expectationOrigins.originLimit = minimock.CallerInfo(1) + + return mmList +} + +// Inspect accepts an inspector function that has same arguments as the NoteRepository.List +func (mmList *mNoteRepositoryMockList) Inspect(f func(ctx context.Context, offset int64, limit int64)) *mNoteRepositoryMockList { + if mmList.mock.inspectFuncList != nil { + mmList.mock.t.Fatalf("Inspect function is already set for NoteRepositoryMock.List") + } + + mmList.mock.inspectFuncList = f + + return mmList +} + +// Return sets up results that will be returned by NoteRepository.List +func (mmList *mNoteRepositoryMockList) Return(npa1 []*model.Note, err error) *NoteRepositoryMock { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteRepositoryMockListExpectation{mock: mmList.mock} + } + mmList.defaultExpectation.results = &NoteRepositoryMockListResults{npa1, err} + mmList.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmList.mock +} + +// Set uses given function f to mock the NoteRepository.List method +func (mmList *mNoteRepositoryMockList) Set(f func(ctx context.Context, offset int64, limit int64) (npa1 []*model.Note, err error)) *NoteRepositoryMock { + if mmList.defaultExpectation != nil { + mmList.mock.t.Fatalf("Default expectation is already set for the NoteRepository.List method") + } + + if len(mmList.expectations) > 0 { + mmList.mock.t.Fatalf("Some expectations are already set for the NoteRepository.List method") + } + + mmList.mock.funcList = f + mmList.mock.funcListOrigin = minimock.CallerInfo(1) + return mmList.mock +} + +// When sets expectation for the NoteRepository.List which will trigger the result defined by the following +// Then helper +func (mmList *mNoteRepositoryMockList) When(ctx context.Context, offset int64, limit int64) *NoteRepositoryMockListExpectation { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteRepositoryMock.List mock is already set by Set") + } + + expectation := &NoteRepositoryMockListExpectation{ + mock: mmList.mock, + params: &NoteRepositoryMockListParams{ctx, offset, limit}, + expectationOrigins: NoteRepositoryMockListExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmList.expectations = append(mmList.expectations, expectation) + return expectation +} + +// Then sets up NoteRepository.List return parameters for the expectation previously defined by the When method +func (e *NoteRepositoryMockListExpectation) Then(npa1 []*model.Note, err error) *NoteRepositoryMock { + e.results = &NoteRepositoryMockListResults{npa1, err} + return e.mock +} + +// Times sets number of times NoteRepository.List should be invoked +func (mmList *mNoteRepositoryMockList) Times(n uint64) *mNoteRepositoryMockList { + if n == 0 { + mmList.mock.t.Fatalf("Times of NoteRepositoryMock.List mock can not be zero") + } + mm_atomic.StoreUint64(&mmList.expectedInvocations, n) + mmList.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmList +} + +func (mmList *mNoteRepositoryMockList) invocationsDone() bool { + if len(mmList.expectations) == 0 && mmList.defaultExpectation == nil && mmList.mock.funcList == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmList.mock.afterListCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmList.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// List implements mm_repository.NoteRepository +func (mmList *NoteRepositoryMock) List(ctx context.Context, offset int64, limit int64) (npa1 []*model.Note, err error) { + mm_atomic.AddUint64(&mmList.beforeListCounter, 1) + defer mm_atomic.AddUint64(&mmList.afterListCounter, 1) + + mmList.t.Helper() + + if mmList.inspectFuncList != nil { + mmList.inspectFuncList(ctx, offset, limit) + } + + mm_params := NoteRepositoryMockListParams{ctx, offset, limit} + + // Record call args + mmList.ListMock.mutex.Lock() + mmList.ListMock.callArgs = append(mmList.ListMock.callArgs, &mm_params) + mmList.ListMock.mutex.Unlock() + + for _, e := range mmList.ListMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.npa1, e.results.err + } + } + + if mmList.ListMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmList.ListMock.defaultExpectation.Counter, 1) + mm_want := mmList.ListMock.defaultExpectation.params + mm_want_ptrs := mmList.ListMock.defaultExpectation.paramPtrs + + mm_got := NoteRepositoryMockListParams{ctx, offset, limit} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmList.t.Errorf("NoteRepositoryMock.List got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.offset != nil && !minimock.Equal(*mm_want_ptrs.offset, mm_got.offset) { + mmList.t.Errorf("NoteRepositoryMock.List got unexpected parameter offset, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.originOffset, *mm_want_ptrs.offset, mm_got.offset, minimock.Diff(*mm_want_ptrs.offset, mm_got.offset)) + } + + if mm_want_ptrs.limit != nil && !minimock.Equal(*mm_want_ptrs.limit, mm_got.limit) { + mmList.t.Errorf("NoteRepositoryMock.List got unexpected parameter limit, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.originLimit, *mm_want_ptrs.limit, mm_got.limit, minimock.Diff(*mm_want_ptrs.limit, mm_got.limit)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmList.t.Errorf("NoteRepositoryMock.List got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmList.ListMock.defaultExpectation.results + if mm_results == nil { + mmList.t.Fatal("No results are set for the NoteRepositoryMock.List") + } + return (*mm_results).npa1, (*mm_results).err + } + if mmList.funcList != nil { + return mmList.funcList(ctx, offset, limit) + } + mmList.t.Fatalf("Unexpected call to NoteRepositoryMock.List. %v %v %v", ctx, offset, limit) + return +} + +// ListAfterCounter returns a count of finished NoteRepositoryMock.List invocations +func (mmList *NoteRepositoryMock) ListAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmList.afterListCounter) +} + +// ListBeforeCounter returns a count of NoteRepositoryMock.List invocations +func (mmList *NoteRepositoryMock) ListBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmList.beforeListCounter) +} + +// Calls returns a list of arguments used in each call to NoteRepositoryMock.List. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmList *mNoteRepositoryMockList) Calls() []*NoteRepositoryMockListParams { + mmList.mutex.RLock() + + argCopy := make([]*NoteRepositoryMockListParams, len(mmList.callArgs)) + copy(argCopy, mmList.callArgs) + + mmList.mutex.RUnlock() + + return argCopy +} + +// MinimockListDone returns true if the count of the List invocations corresponds +// the number of defined expectations +func (m *NoteRepositoryMock) MinimockListDone() bool { + if m.ListMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.ListMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.ListMock.invocationsDone() +} + +// MinimockListInspect logs each unmet expectation +func (m *NoteRepositoryMock) MinimockListInspect() { + for _, e := range m.ListMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.List at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterListCounter := mm_atomic.LoadUint64(&m.afterListCounter) + // if default expectation was set then invocations count should be greater than zero + if m.ListMock.defaultExpectation != nil && afterListCounter < 1 { + if m.ListMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteRepositoryMock.List at\n%s", m.ListMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteRepositoryMock.List at\n%s with params: %#v", m.ListMock.defaultExpectation.expectationOrigins.origin, *m.ListMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcList != nil && afterListCounter < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.List at\n%s", m.funcListOrigin) + } + + if !m.ListMock.invocationsDone() && afterListCounter > 0 { + m.t.Errorf("Expected %d calls to NoteRepositoryMock.List at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.ListMock.expectedInvocations), m.ListMock.expectedInvocationsOrigin, afterListCounter) + } +} + +type mNoteRepositoryMockUpdate struct { + optional bool + mock *NoteRepositoryMock + defaultExpectation *NoteRepositoryMockUpdateExpectation + expectations []*NoteRepositoryMockUpdateExpectation + + callArgs []*NoteRepositoryMockUpdateParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteRepositoryMockUpdateExpectation specifies expectation struct of the NoteRepository.Update +type NoteRepositoryMockUpdateExpectation struct { + mock *NoteRepositoryMock + params *NoteRepositoryMockUpdateParams + paramPtrs *NoteRepositoryMockUpdateParamPtrs + expectationOrigins NoteRepositoryMockUpdateExpectationOrigins + results *NoteRepositoryMockUpdateResults + returnOrigin string + Counter uint64 +} + +// NoteRepositoryMockUpdateParams contains parameters of the NoteRepository.Update +type NoteRepositoryMockUpdateParams struct { + ctx context.Context + info *model.UpdateNote +} + +// NoteRepositoryMockUpdateParamPtrs contains pointers to parameters of the NoteRepository.Update +type NoteRepositoryMockUpdateParamPtrs struct { + ctx *context.Context + info **model.UpdateNote +} + +// NoteRepositoryMockUpdateResults contains results of the NoteRepository.Update +type NoteRepositoryMockUpdateResults struct { + err error +} + +// NoteRepositoryMockUpdateOrigins contains origins of expectations of the NoteRepository.Update +type NoteRepositoryMockUpdateExpectationOrigins struct { + origin string + originCtx string + originInfo string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmUpdate *mNoteRepositoryMockUpdate) Optional() *mNoteRepositoryMockUpdate { + mmUpdate.optional = true + return mmUpdate +} + +// Expect sets up expected params for NoteRepository.Update +func (mmUpdate *mNoteRepositoryMockUpdate) Expect(ctx context.Context, info *model.UpdateNote) *mNoteRepositoryMockUpdate { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteRepositoryMockUpdateExpectation{} + } + + if mmUpdate.defaultExpectation.paramPtrs != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by ExpectParams functions") + } + + mmUpdate.defaultExpectation.params = &NoteRepositoryMockUpdateParams{ctx, info} + mmUpdate.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmUpdate.expectations { + if minimock.Equal(e.params, mmUpdate.defaultExpectation.params) { + mmUpdate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdate.defaultExpectation.params) + } + } + + return mmUpdate +} + +// ExpectCtxParam1 sets up expected param ctx for NoteRepository.Update +func (mmUpdate *mNoteRepositoryMockUpdate) ExpectCtxParam1(ctx context.Context) *mNoteRepositoryMockUpdate { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteRepositoryMockUpdateExpectation{} + } + + if mmUpdate.defaultExpectation.params != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Expect") + } + + if mmUpdate.defaultExpectation.paramPtrs == nil { + mmUpdate.defaultExpectation.paramPtrs = &NoteRepositoryMockUpdateParamPtrs{} + } + mmUpdate.defaultExpectation.paramPtrs.ctx = &ctx + mmUpdate.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmUpdate +} + +// ExpectInfoParam2 sets up expected param info for NoteRepository.Update +func (mmUpdate *mNoteRepositoryMockUpdate) ExpectInfoParam2(info *model.UpdateNote) *mNoteRepositoryMockUpdate { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteRepositoryMockUpdateExpectation{} + } + + if mmUpdate.defaultExpectation.params != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Expect") + } + + if mmUpdate.defaultExpectation.paramPtrs == nil { + mmUpdate.defaultExpectation.paramPtrs = &NoteRepositoryMockUpdateParamPtrs{} + } + mmUpdate.defaultExpectation.paramPtrs.info = &info + mmUpdate.defaultExpectation.expectationOrigins.originInfo = minimock.CallerInfo(1) + + return mmUpdate +} + +// Inspect accepts an inspector function that has same arguments as the NoteRepository.Update +func (mmUpdate *mNoteRepositoryMockUpdate) Inspect(f func(ctx context.Context, info *model.UpdateNote)) *mNoteRepositoryMockUpdate { + if mmUpdate.mock.inspectFuncUpdate != nil { + mmUpdate.mock.t.Fatalf("Inspect function is already set for NoteRepositoryMock.Update") + } + + mmUpdate.mock.inspectFuncUpdate = f + + return mmUpdate +} + +// Return sets up results that will be returned by NoteRepository.Update +func (mmUpdate *mNoteRepositoryMockUpdate) Return(err error) *NoteRepositoryMock { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteRepositoryMockUpdateExpectation{mock: mmUpdate.mock} + } + mmUpdate.defaultExpectation.results = &NoteRepositoryMockUpdateResults{err} + mmUpdate.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmUpdate.mock +} + +// Set uses given function f to mock the NoteRepository.Update method +func (mmUpdate *mNoteRepositoryMockUpdate) Set(f func(ctx context.Context, info *model.UpdateNote) (err error)) *NoteRepositoryMock { + if mmUpdate.defaultExpectation != nil { + mmUpdate.mock.t.Fatalf("Default expectation is already set for the NoteRepository.Update method") + } + + if len(mmUpdate.expectations) > 0 { + mmUpdate.mock.t.Fatalf("Some expectations are already set for the NoteRepository.Update method") + } + + mmUpdate.mock.funcUpdate = f + mmUpdate.mock.funcUpdateOrigin = minimock.CallerInfo(1) + return mmUpdate.mock +} + +// When sets expectation for the NoteRepository.Update which will trigger the result defined by the following +// Then helper +func (mmUpdate *mNoteRepositoryMockUpdate) When(ctx context.Context, info *model.UpdateNote) *NoteRepositoryMockUpdateExpectation { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteRepositoryMock.Update mock is already set by Set") + } + + expectation := &NoteRepositoryMockUpdateExpectation{ + mock: mmUpdate.mock, + params: &NoteRepositoryMockUpdateParams{ctx, info}, + expectationOrigins: NoteRepositoryMockUpdateExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmUpdate.expectations = append(mmUpdate.expectations, expectation) + return expectation +} + +// Then sets up NoteRepository.Update return parameters for the expectation previously defined by the When method +func (e *NoteRepositoryMockUpdateExpectation) Then(err error) *NoteRepositoryMock { + e.results = &NoteRepositoryMockUpdateResults{err} + return e.mock +} + +// Times sets number of times NoteRepository.Update should be invoked +func (mmUpdate *mNoteRepositoryMockUpdate) Times(n uint64) *mNoteRepositoryMockUpdate { + if n == 0 { + mmUpdate.mock.t.Fatalf("Times of NoteRepositoryMock.Update mock can not be zero") + } + mm_atomic.StoreUint64(&mmUpdate.expectedInvocations, n) + mmUpdate.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmUpdate +} + +func (mmUpdate *mNoteRepositoryMockUpdate) invocationsDone() bool { + if len(mmUpdate.expectations) == 0 && mmUpdate.defaultExpectation == nil && mmUpdate.mock.funcUpdate == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmUpdate.mock.afterUpdateCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmUpdate.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Update implements mm_repository.NoteRepository +func (mmUpdate *NoteRepositoryMock) Update(ctx context.Context, info *model.UpdateNote) (err error) { + mm_atomic.AddUint64(&mmUpdate.beforeUpdateCounter, 1) + defer mm_atomic.AddUint64(&mmUpdate.afterUpdateCounter, 1) + + mmUpdate.t.Helper() + + if mmUpdate.inspectFuncUpdate != nil { + mmUpdate.inspectFuncUpdate(ctx, info) + } + + mm_params := NoteRepositoryMockUpdateParams{ctx, info} + + // Record call args + mmUpdate.UpdateMock.mutex.Lock() + mmUpdate.UpdateMock.callArgs = append(mmUpdate.UpdateMock.callArgs, &mm_params) + mmUpdate.UpdateMock.mutex.Unlock() + + for _, e := range mmUpdate.UpdateMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmUpdate.UpdateMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmUpdate.UpdateMock.defaultExpectation.Counter, 1) + mm_want := mmUpdate.UpdateMock.defaultExpectation.params + mm_want_ptrs := mmUpdate.UpdateMock.defaultExpectation.paramPtrs + + mm_got := NoteRepositoryMockUpdateParams{ctx, info} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmUpdate.t.Errorf("NoteRepositoryMock.Update got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmUpdate.UpdateMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.info != nil && !minimock.Equal(*mm_want_ptrs.info, mm_got.info) { + mmUpdate.t.Errorf("NoteRepositoryMock.Update got unexpected parameter info, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmUpdate.UpdateMock.defaultExpectation.expectationOrigins.originInfo, *mm_want_ptrs.info, mm_got.info, minimock.Diff(*mm_want_ptrs.info, mm_got.info)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmUpdate.t.Errorf("NoteRepositoryMock.Update got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmUpdate.UpdateMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmUpdate.UpdateMock.defaultExpectation.results + if mm_results == nil { + mmUpdate.t.Fatal("No results are set for the NoteRepositoryMock.Update") + } + return (*mm_results).err + } + if mmUpdate.funcUpdate != nil { + return mmUpdate.funcUpdate(ctx, info) + } + mmUpdate.t.Fatalf("Unexpected call to NoteRepositoryMock.Update. %v %v", ctx, info) + return +} + +// UpdateAfterCounter returns a count of finished NoteRepositoryMock.Update invocations +func (mmUpdate *NoteRepositoryMock) UpdateAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdate.afterUpdateCounter) +} + +// UpdateBeforeCounter returns a count of NoteRepositoryMock.Update invocations +func (mmUpdate *NoteRepositoryMock) UpdateBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdate.beforeUpdateCounter) +} + +// Calls returns a list of arguments used in each call to NoteRepositoryMock.Update. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmUpdate *mNoteRepositoryMockUpdate) Calls() []*NoteRepositoryMockUpdateParams { + mmUpdate.mutex.RLock() + + argCopy := make([]*NoteRepositoryMockUpdateParams, len(mmUpdate.callArgs)) + copy(argCopy, mmUpdate.callArgs) + + mmUpdate.mutex.RUnlock() + + return argCopy +} + +// MinimockUpdateDone returns true if the count of the Update invocations corresponds +// the number of defined expectations +func (m *NoteRepositoryMock) MinimockUpdateDone() bool { + if m.UpdateMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.UpdateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.UpdateMock.invocationsDone() +} + +// MinimockUpdateInspect logs each unmet expectation +func (m *NoteRepositoryMock) MinimockUpdateInspect() { + for _, e := range m.UpdateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Update at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterUpdateCounter := mm_atomic.LoadUint64(&m.afterUpdateCounter) + // if default expectation was set then invocations count should be greater than zero + if m.UpdateMock.defaultExpectation != nil && afterUpdateCounter < 1 { + if m.UpdateMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteRepositoryMock.Update at\n%s", m.UpdateMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteRepositoryMock.Update at\n%s with params: %#v", m.UpdateMock.defaultExpectation.expectationOrigins.origin, *m.UpdateMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcUpdate != nil && afterUpdateCounter < 1 { + m.t.Errorf("Expected call to NoteRepositoryMock.Update at\n%s", m.funcUpdateOrigin) + } + + if !m.UpdateMock.invocationsDone() && afterUpdateCounter > 0 { + m.t.Errorf("Expected %d calls to NoteRepositoryMock.Update at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.UpdateMock.expectedInvocations), m.UpdateMock.expectedInvocationsOrigin, afterUpdateCounter) + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *NoteRepositoryMock) MinimockFinish() { + m.finishOnce.Do(func() { + if !m.minimockDone() { + m.MinimockCreateInspect() + + m.MinimockDeleteInspect() + + m.MinimockGetInspect() + + m.MinimockListInspect() + + m.MinimockUpdateInspect() + } + }) +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *NoteRepositoryMock) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *NoteRepositoryMock) minimockDone() bool { + done := true + return done && + m.MinimockCreateDone() && + m.MinimockDeleteDone() && + m.MinimockGetDone() && + m.MinimockListDone() && + m.MinimockUpdateDone() +} diff --git a/internal/service/generate.go b/internal/service/generate.go new file mode 100644 index 0000000..042cdf1 --- /dev/null +++ b/internal/service/generate.go @@ -0,0 +1,4 @@ +package service + +//go:generate sh -c "rm -rf mocks && mkdir -p mocks" +//go:generate minimock -i NoteService -o ./mocks/ -s "_minimock.go" diff --git a/internal/service/mocks/note_service_minimock.go b/internal/service/mocks/note_service_minimock.go new file mode 100644 index 0000000..f46a9ae --- /dev/null +++ b/internal/service/mocks/note_service_minimock.go @@ -0,0 +1,1871 @@ +// Code generated by http://github.com/gojuno/minimock (v3.4.0). DO NOT EDIT. + +package mocks + +//go:generate minimock -i github.com/xeeetu/gRPC/internal/service.NoteService -o note_service_minimock.go -n NoteServiceMock -p mocks + +import ( + "context" + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" + "github.com/xeeetu/gRPC/model" +) + +// NoteServiceMock implements mm_service.NoteService +type NoteServiceMock struct { + t minimock.Tester + finishOnce sync.Once + + funcCreate func(ctx context.Context, info *model.NoteInfo) (i1 int64, err error) + funcCreateOrigin string + inspectFuncCreate func(ctx context.Context, info *model.NoteInfo) + afterCreateCounter uint64 + beforeCreateCounter uint64 + CreateMock mNoteServiceMockCreate + + funcDelete func(ctx context.Context, id int64) (err error) + funcDeleteOrigin string + inspectFuncDelete func(ctx context.Context, id int64) + afterDeleteCounter uint64 + beforeDeleteCounter uint64 + DeleteMock mNoteServiceMockDelete + + funcGet func(ctx context.Context, id int64) (np1 *model.Note, err error) + funcGetOrigin string + inspectFuncGet func(ctx context.Context, id int64) + afterGetCounter uint64 + beforeGetCounter uint64 + GetMock mNoteServiceMockGet + + funcList func(ctx context.Context, offset int64, limit int64) (npa1 []*model.Note, err error) + funcListOrigin string + inspectFuncList func(ctx context.Context, offset int64, limit int64) + afterListCounter uint64 + beforeListCounter uint64 + ListMock mNoteServiceMockList + + funcUpdate func(ctx context.Context, info *model.UpdateNote) (err error) + funcUpdateOrigin string + inspectFuncUpdate func(ctx context.Context, info *model.UpdateNote) + afterUpdateCounter uint64 + beforeUpdateCounter uint64 + UpdateMock mNoteServiceMockUpdate +} + +// NewNoteServiceMock returns a mock for mm_service.NoteService +func NewNoteServiceMock(t minimock.Tester) *NoteServiceMock { + m := &NoteServiceMock{t: t} + + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.CreateMock = mNoteServiceMockCreate{mock: m} + m.CreateMock.callArgs = []*NoteServiceMockCreateParams{} + + m.DeleteMock = mNoteServiceMockDelete{mock: m} + m.DeleteMock.callArgs = []*NoteServiceMockDeleteParams{} + + m.GetMock = mNoteServiceMockGet{mock: m} + m.GetMock.callArgs = []*NoteServiceMockGetParams{} + + m.ListMock = mNoteServiceMockList{mock: m} + m.ListMock.callArgs = []*NoteServiceMockListParams{} + + m.UpdateMock = mNoteServiceMockUpdate{mock: m} + m.UpdateMock.callArgs = []*NoteServiceMockUpdateParams{} + + t.Cleanup(m.MinimockFinish) + + return m +} + +type mNoteServiceMockCreate struct { + optional bool + mock *NoteServiceMock + defaultExpectation *NoteServiceMockCreateExpectation + expectations []*NoteServiceMockCreateExpectation + + callArgs []*NoteServiceMockCreateParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteServiceMockCreateExpectation specifies expectation struct of the NoteService.Create +type NoteServiceMockCreateExpectation struct { + mock *NoteServiceMock + params *NoteServiceMockCreateParams + paramPtrs *NoteServiceMockCreateParamPtrs + expectationOrigins NoteServiceMockCreateExpectationOrigins + results *NoteServiceMockCreateResults + returnOrigin string + Counter uint64 +} + +// NoteServiceMockCreateParams contains parameters of the NoteService.Create +type NoteServiceMockCreateParams struct { + ctx context.Context + info *model.NoteInfo +} + +// NoteServiceMockCreateParamPtrs contains pointers to parameters of the NoteService.Create +type NoteServiceMockCreateParamPtrs struct { + ctx *context.Context + info **model.NoteInfo +} + +// NoteServiceMockCreateResults contains results of the NoteService.Create +type NoteServiceMockCreateResults struct { + i1 int64 + err error +} + +// NoteServiceMockCreateOrigins contains origins of expectations of the NoteService.Create +type NoteServiceMockCreateExpectationOrigins struct { + origin string + originCtx string + originInfo string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmCreate *mNoteServiceMockCreate) Optional() *mNoteServiceMockCreate { + mmCreate.optional = true + return mmCreate +} + +// Expect sets up expected params for NoteService.Create +func (mmCreate *mNoteServiceMockCreate) Expect(ctx context.Context, info *model.NoteInfo) *mNoteServiceMockCreate { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteServiceMockCreateExpectation{} + } + + if mmCreate.defaultExpectation.paramPtrs != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by ExpectParams functions") + } + + mmCreate.defaultExpectation.params = &NoteServiceMockCreateParams{ctx, info} + mmCreate.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmCreate.expectations { + if minimock.Equal(e.params, mmCreate.defaultExpectation.params) { + mmCreate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreate.defaultExpectation.params) + } + } + + return mmCreate +} + +// ExpectCtxParam1 sets up expected param ctx for NoteService.Create +func (mmCreate *mNoteServiceMockCreate) ExpectCtxParam1(ctx context.Context) *mNoteServiceMockCreate { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteServiceMockCreateExpectation{} + } + + if mmCreate.defaultExpectation.params != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Expect") + } + + if mmCreate.defaultExpectation.paramPtrs == nil { + mmCreate.defaultExpectation.paramPtrs = &NoteServiceMockCreateParamPtrs{} + } + mmCreate.defaultExpectation.paramPtrs.ctx = &ctx + mmCreate.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmCreate +} + +// ExpectInfoParam2 sets up expected param info for NoteService.Create +func (mmCreate *mNoteServiceMockCreate) ExpectInfoParam2(info *model.NoteInfo) *mNoteServiceMockCreate { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteServiceMockCreateExpectation{} + } + + if mmCreate.defaultExpectation.params != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Expect") + } + + if mmCreate.defaultExpectation.paramPtrs == nil { + mmCreate.defaultExpectation.paramPtrs = &NoteServiceMockCreateParamPtrs{} + } + mmCreate.defaultExpectation.paramPtrs.info = &info + mmCreate.defaultExpectation.expectationOrigins.originInfo = minimock.CallerInfo(1) + + return mmCreate +} + +// Inspect accepts an inspector function that has same arguments as the NoteService.Create +func (mmCreate *mNoteServiceMockCreate) Inspect(f func(ctx context.Context, info *model.NoteInfo)) *mNoteServiceMockCreate { + if mmCreate.mock.inspectFuncCreate != nil { + mmCreate.mock.t.Fatalf("Inspect function is already set for NoteServiceMock.Create") + } + + mmCreate.mock.inspectFuncCreate = f + + return mmCreate +} + +// Return sets up results that will be returned by NoteService.Create +func (mmCreate *mNoteServiceMockCreate) Return(i1 int64, err error) *NoteServiceMock { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Set") + } + + if mmCreate.defaultExpectation == nil { + mmCreate.defaultExpectation = &NoteServiceMockCreateExpectation{mock: mmCreate.mock} + } + mmCreate.defaultExpectation.results = &NoteServiceMockCreateResults{i1, err} + mmCreate.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmCreate.mock +} + +// Set uses given function f to mock the NoteService.Create method +func (mmCreate *mNoteServiceMockCreate) Set(f func(ctx context.Context, info *model.NoteInfo) (i1 int64, err error)) *NoteServiceMock { + if mmCreate.defaultExpectation != nil { + mmCreate.mock.t.Fatalf("Default expectation is already set for the NoteService.Create method") + } + + if len(mmCreate.expectations) > 0 { + mmCreate.mock.t.Fatalf("Some expectations are already set for the NoteService.Create method") + } + + mmCreate.mock.funcCreate = f + mmCreate.mock.funcCreateOrigin = minimock.CallerInfo(1) + return mmCreate.mock +} + +// When sets expectation for the NoteService.Create which will trigger the result defined by the following +// Then helper +func (mmCreate *mNoteServiceMockCreate) When(ctx context.Context, info *model.NoteInfo) *NoteServiceMockCreateExpectation { + if mmCreate.mock.funcCreate != nil { + mmCreate.mock.t.Fatalf("NoteServiceMock.Create mock is already set by Set") + } + + expectation := &NoteServiceMockCreateExpectation{ + mock: mmCreate.mock, + params: &NoteServiceMockCreateParams{ctx, info}, + expectationOrigins: NoteServiceMockCreateExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmCreate.expectations = append(mmCreate.expectations, expectation) + return expectation +} + +// Then sets up NoteService.Create return parameters for the expectation previously defined by the When method +func (e *NoteServiceMockCreateExpectation) Then(i1 int64, err error) *NoteServiceMock { + e.results = &NoteServiceMockCreateResults{i1, err} + return e.mock +} + +// Times sets number of times NoteService.Create should be invoked +func (mmCreate *mNoteServiceMockCreate) Times(n uint64) *mNoteServiceMockCreate { + if n == 0 { + mmCreate.mock.t.Fatalf("Times of NoteServiceMock.Create mock can not be zero") + } + mm_atomic.StoreUint64(&mmCreate.expectedInvocations, n) + mmCreate.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmCreate +} + +func (mmCreate *mNoteServiceMockCreate) invocationsDone() bool { + if len(mmCreate.expectations) == 0 && mmCreate.defaultExpectation == nil && mmCreate.mock.funcCreate == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmCreate.mock.afterCreateCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmCreate.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Create implements mm_service.NoteService +func (mmCreate *NoteServiceMock) Create(ctx context.Context, info *model.NoteInfo) (i1 int64, err error) { + mm_atomic.AddUint64(&mmCreate.beforeCreateCounter, 1) + defer mm_atomic.AddUint64(&mmCreate.afterCreateCounter, 1) + + mmCreate.t.Helper() + + if mmCreate.inspectFuncCreate != nil { + mmCreate.inspectFuncCreate(ctx, info) + } + + mm_params := NoteServiceMockCreateParams{ctx, info} + + // Record call args + mmCreate.CreateMock.mutex.Lock() + mmCreate.CreateMock.callArgs = append(mmCreate.CreateMock.callArgs, &mm_params) + mmCreate.CreateMock.mutex.Unlock() + + for _, e := range mmCreate.CreateMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.i1, e.results.err + } + } + + if mmCreate.CreateMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmCreate.CreateMock.defaultExpectation.Counter, 1) + mm_want := mmCreate.CreateMock.defaultExpectation.params + mm_want_ptrs := mmCreate.CreateMock.defaultExpectation.paramPtrs + + mm_got := NoteServiceMockCreateParams{ctx, info} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmCreate.t.Errorf("NoteServiceMock.Create got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmCreate.CreateMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.info != nil && !minimock.Equal(*mm_want_ptrs.info, mm_got.info) { + mmCreate.t.Errorf("NoteServiceMock.Create got unexpected parameter info, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmCreate.CreateMock.defaultExpectation.expectationOrigins.originInfo, *mm_want_ptrs.info, mm_got.info, minimock.Diff(*mm_want_ptrs.info, mm_got.info)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmCreate.t.Errorf("NoteServiceMock.Create got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmCreate.CreateMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmCreate.CreateMock.defaultExpectation.results + if mm_results == nil { + mmCreate.t.Fatal("No results are set for the NoteServiceMock.Create") + } + return (*mm_results).i1, (*mm_results).err + } + if mmCreate.funcCreate != nil { + return mmCreate.funcCreate(ctx, info) + } + mmCreate.t.Fatalf("Unexpected call to NoteServiceMock.Create. %v %v", ctx, info) + return +} + +// CreateAfterCounter returns a count of finished NoteServiceMock.Create invocations +func (mmCreate *NoteServiceMock) CreateAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreate.afterCreateCounter) +} + +// CreateBeforeCounter returns a count of NoteServiceMock.Create invocations +func (mmCreate *NoteServiceMock) CreateBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreate.beforeCreateCounter) +} + +// Calls returns a list of arguments used in each call to NoteServiceMock.Create. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmCreate *mNoteServiceMockCreate) Calls() []*NoteServiceMockCreateParams { + mmCreate.mutex.RLock() + + argCopy := make([]*NoteServiceMockCreateParams, len(mmCreate.callArgs)) + copy(argCopy, mmCreate.callArgs) + + mmCreate.mutex.RUnlock() + + return argCopy +} + +// MinimockCreateDone returns true if the count of the Create invocations corresponds +// the number of defined expectations +func (m *NoteServiceMock) MinimockCreateDone() bool { + if m.CreateMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.CreateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.CreateMock.invocationsDone() +} + +// MinimockCreateInspect logs each unmet expectation +func (m *NoteServiceMock) MinimockCreateInspect() { + for _, e := range m.CreateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Create at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterCreateCounter := mm_atomic.LoadUint64(&m.afterCreateCounter) + // if default expectation was set then invocations count should be greater than zero + if m.CreateMock.defaultExpectation != nil && afterCreateCounter < 1 { + if m.CreateMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteServiceMock.Create at\n%s", m.CreateMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteServiceMock.Create at\n%s with params: %#v", m.CreateMock.defaultExpectation.expectationOrigins.origin, *m.CreateMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcCreate != nil && afterCreateCounter < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Create at\n%s", m.funcCreateOrigin) + } + + if !m.CreateMock.invocationsDone() && afterCreateCounter > 0 { + m.t.Errorf("Expected %d calls to NoteServiceMock.Create at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.CreateMock.expectedInvocations), m.CreateMock.expectedInvocationsOrigin, afterCreateCounter) + } +} + +type mNoteServiceMockDelete struct { + optional bool + mock *NoteServiceMock + defaultExpectation *NoteServiceMockDeleteExpectation + expectations []*NoteServiceMockDeleteExpectation + + callArgs []*NoteServiceMockDeleteParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteServiceMockDeleteExpectation specifies expectation struct of the NoteService.Delete +type NoteServiceMockDeleteExpectation struct { + mock *NoteServiceMock + params *NoteServiceMockDeleteParams + paramPtrs *NoteServiceMockDeleteParamPtrs + expectationOrigins NoteServiceMockDeleteExpectationOrigins + results *NoteServiceMockDeleteResults + returnOrigin string + Counter uint64 +} + +// NoteServiceMockDeleteParams contains parameters of the NoteService.Delete +type NoteServiceMockDeleteParams struct { + ctx context.Context + id int64 +} + +// NoteServiceMockDeleteParamPtrs contains pointers to parameters of the NoteService.Delete +type NoteServiceMockDeleteParamPtrs struct { + ctx *context.Context + id *int64 +} + +// NoteServiceMockDeleteResults contains results of the NoteService.Delete +type NoteServiceMockDeleteResults struct { + err error +} + +// NoteServiceMockDeleteOrigins contains origins of expectations of the NoteService.Delete +type NoteServiceMockDeleteExpectationOrigins struct { + origin string + originCtx string + originId string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmDelete *mNoteServiceMockDelete) Optional() *mNoteServiceMockDelete { + mmDelete.optional = true + return mmDelete +} + +// Expect sets up expected params for NoteService.Delete +func (mmDelete *mNoteServiceMockDelete) Expect(ctx context.Context, id int64) *mNoteServiceMockDelete { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteServiceMockDeleteExpectation{} + } + + if mmDelete.defaultExpectation.paramPtrs != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by ExpectParams functions") + } + + mmDelete.defaultExpectation.params = &NoteServiceMockDeleteParams{ctx, id} + mmDelete.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmDelete.expectations { + if minimock.Equal(e.params, mmDelete.defaultExpectation.params) { + mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params) + } + } + + return mmDelete +} + +// ExpectCtxParam1 sets up expected param ctx for NoteService.Delete +func (mmDelete *mNoteServiceMockDelete) ExpectCtxParam1(ctx context.Context) *mNoteServiceMockDelete { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteServiceMockDeleteExpectation{} + } + + if mmDelete.defaultExpectation.params != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Expect") + } + + if mmDelete.defaultExpectation.paramPtrs == nil { + mmDelete.defaultExpectation.paramPtrs = &NoteServiceMockDeleteParamPtrs{} + } + mmDelete.defaultExpectation.paramPtrs.ctx = &ctx + mmDelete.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmDelete +} + +// ExpectIdParam2 sets up expected param id for NoteService.Delete +func (mmDelete *mNoteServiceMockDelete) ExpectIdParam2(id int64) *mNoteServiceMockDelete { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteServiceMockDeleteExpectation{} + } + + if mmDelete.defaultExpectation.params != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Expect") + } + + if mmDelete.defaultExpectation.paramPtrs == nil { + mmDelete.defaultExpectation.paramPtrs = &NoteServiceMockDeleteParamPtrs{} + } + mmDelete.defaultExpectation.paramPtrs.id = &id + mmDelete.defaultExpectation.expectationOrigins.originId = minimock.CallerInfo(1) + + return mmDelete +} + +// Inspect accepts an inspector function that has same arguments as the NoteService.Delete +func (mmDelete *mNoteServiceMockDelete) Inspect(f func(ctx context.Context, id int64)) *mNoteServiceMockDelete { + if mmDelete.mock.inspectFuncDelete != nil { + mmDelete.mock.t.Fatalf("Inspect function is already set for NoteServiceMock.Delete") + } + + mmDelete.mock.inspectFuncDelete = f + + return mmDelete +} + +// Return sets up results that will be returned by NoteService.Delete +func (mmDelete *mNoteServiceMockDelete) Return(err error) *NoteServiceMock { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Set") + } + + if mmDelete.defaultExpectation == nil { + mmDelete.defaultExpectation = &NoteServiceMockDeleteExpectation{mock: mmDelete.mock} + } + mmDelete.defaultExpectation.results = &NoteServiceMockDeleteResults{err} + mmDelete.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmDelete.mock +} + +// Set uses given function f to mock the NoteService.Delete method +func (mmDelete *mNoteServiceMockDelete) Set(f func(ctx context.Context, id int64) (err error)) *NoteServiceMock { + if mmDelete.defaultExpectation != nil { + mmDelete.mock.t.Fatalf("Default expectation is already set for the NoteService.Delete method") + } + + if len(mmDelete.expectations) > 0 { + mmDelete.mock.t.Fatalf("Some expectations are already set for the NoteService.Delete method") + } + + mmDelete.mock.funcDelete = f + mmDelete.mock.funcDeleteOrigin = minimock.CallerInfo(1) + return mmDelete.mock +} + +// When sets expectation for the NoteService.Delete which will trigger the result defined by the following +// Then helper +func (mmDelete *mNoteServiceMockDelete) When(ctx context.Context, id int64) *NoteServiceMockDeleteExpectation { + if mmDelete.mock.funcDelete != nil { + mmDelete.mock.t.Fatalf("NoteServiceMock.Delete mock is already set by Set") + } + + expectation := &NoteServiceMockDeleteExpectation{ + mock: mmDelete.mock, + params: &NoteServiceMockDeleteParams{ctx, id}, + expectationOrigins: NoteServiceMockDeleteExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmDelete.expectations = append(mmDelete.expectations, expectation) + return expectation +} + +// Then sets up NoteService.Delete return parameters for the expectation previously defined by the When method +func (e *NoteServiceMockDeleteExpectation) Then(err error) *NoteServiceMock { + e.results = &NoteServiceMockDeleteResults{err} + return e.mock +} + +// Times sets number of times NoteService.Delete should be invoked +func (mmDelete *mNoteServiceMockDelete) Times(n uint64) *mNoteServiceMockDelete { + if n == 0 { + mmDelete.mock.t.Fatalf("Times of NoteServiceMock.Delete mock can not be zero") + } + mm_atomic.StoreUint64(&mmDelete.expectedInvocations, n) + mmDelete.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmDelete +} + +func (mmDelete *mNoteServiceMockDelete) invocationsDone() bool { + if len(mmDelete.expectations) == 0 && mmDelete.defaultExpectation == nil && mmDelete.mock.funcDelete == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmDelete.mock.afterDeleteCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmDelete.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Delete implements mm_service.NoteService +func (mmDelete *NoteServiceMock) Delete(ctx context.Context, id int64) (err error) { + mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1) + defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1) + + mmDelete.t.Helper() + + if mmDelete.inspectFuncDelete != nil { + mmDelete.inspectFuncDelete(ctx, id) + } + + mm_params := NoteServiceMockDeleteParams{ctx, id} + + // Record call args + mmDelete.DeleteMock.mutex.Lock() + mmDelete.DeleteMock.callArgs = append(mmDelete.DeleteMock.callArgs, &mm_params) + mmDelete.DeleteMock.mutex.Unlock() + + for _, e := range mmDelete.DeleteMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmDelete.DeleteMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmDelete.DeleteMock.defaultExpectation.Counter, 1) + mm_want := mmDelete.DeleteMock.defaultExpectation.params + mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs + + mm_got := NoteServiceMockDeleteParams{ctx, id} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmDelete.t.Errorf("NoteServiceMock.Delete got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmDelete.DeleteMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) { + mmDelete.t.Errorf("NoteServiceMock.Delete got unexpected parameter id, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmDelete.DeleteMock.defaultExpectation.expectationOrigins.originId, *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmDelete.t.Errorf("NoteServiceMock.Delete got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmDelete.DeleteMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmDelete.DeleteMock.defaultExpectation.results + if mm_results == nil { + mmDelete.t.Fatal("No results are set for the NoteServiceMock.Delete") + } + return (*mm_results).err + } + if mmDelete.funcDelete != nil { + return mmDelete.funcDelete(ctx, id) + } + mmDelete.t.Fatalf("Unexpected call to NoteServiceMock.Delete. %v %v", ctx, id) + return +} + +// DeleteAfterCounter returns a count of finished NoteServiceMock.Delete invocations +func (mmDelete *NoteServiceMock) DeleteAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmDelete.afterDeleteCounter) +} + +// DeleteBeforeCounter returns a count of NoteServiceMock.Delete invocations +func (mmDelete *NoteServiceMock) DeleteBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmDelete.beforeDeleteCounter) +} + +// Calls returns a list of arguments used in each call to NoteServiceMock.Delete. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmDelete *mNoteServiceMockDelete) Calls() []*NoteServiceMockDeleteParams { + mmDelete.mutex.RLock() + + argCopy := make([]*NoteServiceMockDeleteParams, len(mmDelete.callArgs)) + copy(argCopy, mmDelete.callArgs) + + mmDelete.mutex.RUnlock() + + return argCopy +} + +// MinimockDeleteDone returns true if the count of the Delete invocations corresponds +// the number of defined expectations +func (m *NoteServiceMock) MinimockDeleteDone() bool { + if m.DeleteMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.DeleteMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.DeleteMock.invocationsDone() +} + +// MinimockDeleteInspect logs each unmet expectation +func (m *NoteServiceMock) MinimockDeleteInspect() { + for _, e := range m.DeleteMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Delete at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterDeleteCounter := mm_atomic.LoadUint64(&m.afterDeleteCounter) + // if default expectation was set then invocations count should be greater than zero + if m.DeleteMock.defaultExpectation != nil && afterDeleteCounter < 1 { + if m.DeleteMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteServiceMock.Delete at\n%s", m.DeleteMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteServiceMock.Delete at\n%s with params: %#v", m.DeleteMock.defaultExpectation.expectationOrigins.origin, *m.DeleteMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcDelete != nil && afterDeleteCounter < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Delete at\n%s", m.funcDeleteOrigin) + } + + if !m.DeleteMock.invocationsDone() && afterDeleteCounter > 0 { + m.t.Errorf("Expected %d calls to NoteServiceMock.Delete at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.DeleteMock.expectedInvocations), m.DeleteMock.expectedInvocationsOrigin, afterDeleteCounter) + } +} + +type mNoteServiceMockGet struct { + optional bool + mock *NoteServiceMock + defaultExpectation *NoteServiceMockGetExpectation + expectations []*NoteServiceMockGetExpectation + + callArgs []*NoteServiceMockGetParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteServiceMockGetExpectation specifies expectation struct of the NoteService.Get +type NoteServiceMockGetExpectation struct { + mock *NoteServiceMock + params *NoteServiceMockGetParams + paramPtrs *NoteServiceMockGetParamPtrs + expectationOrigins NoteServiceMockGetExpectationOrigins + results *NoteServiceMockGetResults + returnOrigin string + Counter uint64 +} + +// NoteServiceMockGetParams contains parameters of the NoteService.Get +type NoteServiceMockGetParams struct { + ctx context.Context + id int64 +} + +// NoteServiceMockGetParamPtrs contains pointers to parameters of the NoteService.Get +type NoteServiceMockGetParamPtrs struct { + ctx *context.Context + id *int64 +} + +// NoteServiceMockGetResults contains results of the NoteService.Get +type NoteServiceMockGetResults struct { + np1 *model.Note + err error +} + +// NoteServiceMockGetOrigins contains origins of expectations of the NoteService.Get +type NoteServiceMockGetExpectationOrigins struct { + origin string + originCtx string + originId string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmGet *mNoteServiceMockGet) Optional() *mNoteServiceMockGet { + mmGet.optional = true + return mmGet +} + +// Expect sets up expected params for NoteService.Get +func (mmGet *mNoteServiceMockGet) Expect(ctx context.Context, id int64) *mNoteServiceMockGet { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteServiceMockGetExpectation{} + } + + if mmGet.defaultExpectation.paramPtrs != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by ExpectParams functions") + } + + mmGet.defaultExpectation.params = &NoteServiceMockGetParams{ctx, id} + mmGet.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmGet.expectations { + if minimock.Equal(e.params, mmGet.defaultExpectation.params) { + mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params) + } + } + + return mmGet +} + +// ExpectCtxParam1 sets up expected param ctx for NoteService.Get +func (mmGet *mNoteServiceMockGet) ExpectCtxParam1(ctx context.Context) *mNoteServiceMockGet { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteServiceMockGetExpectation{} + } + + if mmGet.defaultExpectation.params != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Expect") + } + + if mmGet.defaultExpectation.paramPtrs == nil { + mmGet.defaultExpectation.paramPtrs = &NoteServiceMockGetParamPtrs{} + } + mmGet.defaultExpectation.paramPtrs.ctx = &ctx + mmGet.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmGet +} + +// ExpectIdParam2 sets up expected param id for NoteService.Get +func (mmGet *mNoteServiceMockGet) ExpectIdParam2(id int64) *mNoteServiceMockGet { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteServiceMockGetExpectation{} + } + + if mmGet.defaultExpectation.params != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Expect") + } + + if mmGet.defaultExpectation.paramPtrs == nil { + mmGet.defaultExpectation.paramPtrs = &NoteServiceMockGetParamPtrs{} + } + mmGet.defaultExpectation.paramPtrs.id = &id + mmGet.defaultExpectation.expectationOrigins.originId = minimock.CallerInfo(1) + + return mmGet +} + +// Inspect accepts an inspector function that has same arguments as the NoteService.Get +func (mmGet *mNoteServiceMockGet) Inspect(f func(ctx context.Context, id int64)) *mNoteServiceMockGet { + if mmGet.mock.inspectFuncGet != nil { + mmGet.mock.t.Fatalf("Inspect function is already set for NoteServiceMock.Get") + } + + mmGet.mock.inspectFuncGet = f + + return mmGet +} + +// Return sets up results that will be returned by NoteService.Get +func (mmGet *mNoteServiceMockGet) Return(np1 *model.Note, err error) *NoteServiceMock { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Set") + } + + if mmGet.defaultExpectation == nil { + mmGet.defaultExpectation = &NoteServiceMockGetExpectation{mock: mmGet.mock} + } + mmGet.defaultExpectation.results = &NoteServiceMockGetResults{np1, err} + mmGet.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmGet.mock +} + +// Set uses given function f to mock the NoteService.Get method +func (mmGet *mNoteServiceMockGet) Set(f func(ctx context.Context, id int64) (np1 *model.Note, err error)) *NoteServiceMock { + if mmGet.defaultExpectation != nil { + mmGet.mock.t.Fatalf("Default expectation is already set for the NoteService.Get method") + } + + if len(mmGet.expectations) > 0 { + mmGet.mock.t.Fatalf("Some expectations are already set for the NoteService.Get method") + } + + mmGet.mock.funcGet = f + mmGet.mock.funcGetOrigin = minimock.CallerInfo(1) + return mmGet.mock +} + +// When sets expectation for the NoteService.Get which will trigger the result defined by the following +// Then helper +func (mmGet *mNoteServiceMockGet) When(ctx context.Context, id int64) *NoteServiceMockGetExpectation { + if mmGet.mock.funcGet != nil { + mmGet.mock.t.Fatalf("NoteServiceMock.Get mock is already set by Set") + } + + expectation := &NoteServiceMockGetExpectation{ + mock: mmGet.mock, + params: &NoteServiceMockGetParams{ctx, id}, + expectationOrigins: NoteServiceMockGetExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmGet.expectations = append(mmGet.expectations, expectation) + return expectation +} + +// Then sets up NoteService.Get return parameters for the expectation previously defined by the When method +func (e *NoteServiceMockGetExpectation) Then(np1 *model.Note, err error) *NoteServiceMock { + e.results = &NoteServiceMockGetResults{np1, err} + return e.mock +} + +// Times sets number of times NoteService.Get should be invoked +func (mmGet *mNoteServiceMockGet) Times(n uint64) *mNoteServiceMockGet { + if n == 0 { + mmGet.mock.t.Fatalf("Times of NoteServiceMock.Get mock can not be zero") + } + mm_atomic.StoreUint64(&mmGet.expectedInvocations, n) + mmGet.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmGet +} + +func (mmGet *mNoteServiceMockGet) invocationsDone() bool { + if len(mmGet.expectations) == 0 && mmGet.defaultExpectation == nil && mmGet.mock.funcGet == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGet.mock.afterGetCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGet.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Get implements mm_service.NoteService +func (mmGet *NoteServiceMock) Get(ctx context.Context, id int64) (np1 *model.Note, err error) { + mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1) + defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1) + + mmGet.t.Helper() + + if mmGet.inspectFuncGet != nil { + mmGet.inspectFuncGet(ctx, id) + } + + mm_params := NoteServiceMockGetParams{ctx, id} + + // Record call args + mmGet.GetMock.mutex.Lock() + mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, &mm_params) + mmGet.GetMock.mutex.Unlock() + + for _, e := range mmGet.GetMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.np1, e.results.err + } + } + + if mmGet.GetMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1) + mm_want := mmGet.GetMock.defaultExpectation.params + mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs + + mm_got := NoteServiceMockGetParams{ctx, id} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGet.t.Errorf("NoteServiceMock.Get got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmGet.GetMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) { + mmGet.t.Errorf("NoteServiceMock.Get got unexpected parameter id, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmGet.GetMock.defaultExpectation.expectationOrigins.originId, *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGet.t.Errorf("NoteServiceMock.Get got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmGet.GetMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGet.GetMock.defaultExpectation.results + if mm_results == nil { + mmGet.t.Fatal("No results are set for the NoteServiceMock.Get") + } + return (*mm_results).np1, (*mm_results).err + } + if mmGet.funcGet != nil { + return mmGet.funcGet(ctx, id) + } + mmGet.t.Fatalf("Unexpected call to NoteServiceMock.Get. %v %v", ctx, id) + return +} + +// GetAfterCounter returns a count of finished NoteServiceMock.Get invocations +func (mmGet *NoteServiceMock) GetAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGet.afterGetCounter) +} + +// GetBeforeCounter returns a count of NoteServiceMock.Get invocations +func (mmGet *NoteServiceMock) GetBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGet.beforeGetCounter) +} + +// Calls returns a list of arguments used in each call to NoteServiceMock.Get. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGet *mNoteServiceMockGet) Calls() []*NoteServiceMockGetParams { + mmGet.mutex.RLock() + + argCopy := make([]*NoteServiceMockGetParams, len(mmGet.callArgs)) + copy(argCopy, mmGet.callArgs) + + mmGet.mutex.RUnlock() + + return argCopy +} + +// MinimockGetDone returns true if the count of the Get invocations corresponds +// the number of defined expectations +func (m *NoteServiceMock) MinimockGetDone() bool { + if m.GetMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.GetMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetMock.invocationsDone() +} + +// MinimockGetInspect logs each unmet expectation +func (m *NoteServiceMock) MinimockGetInspect() { + for _, e := range m.GetMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Get at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterGetCounter := mm_atomic.LoadUint64(&m.afterGetCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetMock.defaultExpectation != nil && afterGetCounter < 1 { + if m.GetMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteServiceMock.Get at\n%s", m.GetMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteServiceMock.Get at\n%s with params: %#v", m.GetMock.defaultExpectation.expectationOrigins.origin, *m.GetMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGet != nil && afterGetCounter < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Get at\n%s", m.funcGetOrigin) + } + + if !m.GetMock.invocationsDone() && afterGetCounter > 0 { + m.t.Errorf("Expected %d calls to NoteServiceMock.Get at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.GetMock.expectedInvocations), m.GetMock.expectedInvocationsOrigin, afterGetCounter) + } +} + +type mNoteServiceMockList struct { + optional bool + mock *NoteServiceMock + defaultExpectation *NoteServiceMockListExpectation + expectations []*NoteServiceMockListExpectation + + callArgs []*NoteServiceMockListParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteServiceMockListExpectation specifies expectation struct of the NoteService.List +type NoteServiceMockListExpectation struct { + mock *NoteServiceMock + params *NoteServiceMockListParams + paramPtrs *NoteServiceMockListParamPtrs + expectationOrigins NoteServiceMockListExpectationOrigins + results *NoteServiceMockListResults + returnOrigin string + Counter uint64 +} + +// NoteServiceMockListParams contains parameters of the NoteService.List +type NoteServiceMockListParams struct { + ctx context.Context + offset int64 + limit int64 +} + +// NoteServiceMockListParamPtrs contains pointers to parameters of the NoteService.List +type NoteServiceMockListParamPtrs struct { + ctx *context.Context + offset *int64 + limit *int64 +} + +// NoteServiceMockListResults contains results of the NoteService.List +type NoteServiceMockListResults struct { + npa1 []*model.Note + err error +} + +// NoteServiceMockListOrigins contains origins of expectations of the NoteService.List +type NoteServiceMockListExpectationOrigins struct { + origin string + originCtx string + originOffset string + originLimit string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmList *mNoteServiceMockList) Optional() *mNoteServiceMockList { + mmList.optional = true + return mmList +} + +// Expect sets up expected params for NoteService.List +func (mmList *mNoteServiceMockList) Expect(ctx context.Context, offset int64, limit int64) *mNoteServiceMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteServiceMockListExpectation{} + } + + if mmList.defaultExpectation.paramPtrs != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by ExpectParams functions") + } + + mmList.defaultExpectation.params = &NoteServiceMockListParams{ctx, offset, limit} + mmList.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmList.expectations { + if minimock.Equal(e.params, mmList.defaultExpectation.params) { + mmList.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmList.defaultExpectation.params) + } + } + + return mmList +} + +// ExpectCtxParam1 sets up expected param ctx for NoteService.List +func (mmList *mNoteServiceMockList) ExpectCtxParam1(ctx context.Context) *mNoteServiceMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteServiceMockListExpectation{} + } + + if mmList.defaultExpectation.params != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Expect") + } + + if mmList.defaultExpectation.paramPtrs == nil { + mmList.defaultExpectation.paramPtrs = &NoteServiceMockListParamPtrs{} + } + mmList.defaultExpectation.paramPtrs.ctx = &ctx + mmList.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmList +} + +// ExpectOffsetParam2 sets up expected param offset for NoteService.List +func (mmList *mNoteServiceMockList) ExpectOffsetParam2(offset int64) *mNoteServiceMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteServiceMockListExpectation{} + } + + if mmList.defaultExpectation.params != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Expect") + } + + if mmList.defaultExpectation.paramPtrs == nil { + mmList.defaultExpectation.paramPtrs = &NoteServiceMockListParamPtrs{} + } + mmList.defaultExpectation.paramPtrs.offset = &offset + mmList.defaultExpectation.expectationOrigins.originOffset = minimock.CallerInfo(1) + + return mmList +} + +// ExpectLimitParam3 sets up expected param limit for NoteService.List +func (mmList *mNoteServiceMockList) ExpectLimitParam3(limit int64) *mNoteServiceMockList { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteServiceMockListExpectation{} + } + + if mmList.defaultExpectation.params != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Expect") + } + + if mmList.defaultExpectation.paramPtrs == nil { + mmList.defaultExpectation.paramPtrs = &NoteServiceMockListParamPtrs{} + } + mmList.defaultExpectation.paramPtrs.limit = &limit + mmList.defaultExpectation.expectationOrigins.originLimit = minimock.CallerInfo(1) + + return mmList +} + +// Inspect accepts an inspector function that has same arguments as the NoteService.List +func (mmList *mNoteServiceMockList) Inspect(f func(ctx context.Context, offset int64, limit int64)) *mNoteServiceMockList { + if mmList.mock.inspectFuncList != nil { + mmList.mock.t.Fatalf("Inspect function is already set for NoteServiceMock.List") + } + + mmList.mock.inspectFuncList = f + + return mmList +} + +// Return sets up results that will be returned by NoteService.List +func (mmList *mNoteServiceMockList) Return(npa1 []*model.Note, err error) *NoteServiceMock { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Set") + } + + if mmList.defaultExpectation == nil { + mmList.defaultExpectation = &NoteServiceMockListExpectation{mock: mmList.mock} + } + mmList.defaultExpectation.results = &NoteServiceMockListResults{npa1, err} + mmList.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmList.mock +} + +// Set uses given function f to mock the NoteService.List method +func (mmList *mNoteServiceMockList) Set(f func(ctx context.Context, offset int64, limit int64) (npa1 []*model.Note, err error)) *NoteServiceMock { + if mmList.defaultExpectation != nil { + mmList.mock.t.Fatalf("Default expectation is already set for the NoteService.List method") + } + + if len(mmList.expectations) > 0 { + mmList.mock.t.Fatalf("Some expectations are already set for the NoteService.List method") + } + + mmList.mock.funcList = f + mmList.mock.funcListOrigin = minimock.CallerInfo(1) + return mmList.mock +} + +// When sets expectation for the NoteService.List which will trigger the result defined by the following +// Then helper +func (mmList *mNoteServiceMockList) When(ctx context.Context, offset int64, limit int64) *NoteServiceMockListExpectation { + if mmList.mock.funcList != nil { + mmList.mock.t.Fatalf("NoteServiceMock.List mock is already set by Set") + } + + expectation := &NoteServiceMockListExpectation{ + mock: mmList.mock, + params: &NoteServiceMockListParams{ctx, offset, limit}, + expectationOrigins: NoteServiceMockListExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmList.expectations = append(mmList.expectations, expectation) + return expectation +} + +// Then sets up NoteService.List return parameters for the expectation previously defined by the When method +func (e *NoteServiceMockListExpectation) Then(npa1 []*model.Note, err error) *NoteServiceMock { + e.results = &NoteServiceMockListResults{npa1, err} + return e.mock +} + +// Times sets number of times NoteService.List should be invoked +func (mmList *mNoteServiceMockList) Times(n uint64) *mNoteServiceMockList { + if n == 0 { + mmList.mock.t.Fatalf("Times of NoteServiceMock.List mock can not be zero") + } + mm_atomic.StoreUint64(&mmList.expectedInvocations, n) + mmList.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmList +} + +func (mmList *mNoteServiceMockList) invocationsDone() bool { + if len(mmList.expectations) == 0 && mmList.defaultExpectation == nil && mmList.mock.funcList == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmList.mock.afterListCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmList.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// List implements mm_service.NoteService +func (mmList *NoteServiceMock) List(ctx context.Context, offset int64, limit int64) (npa1 []*model.Note, err error) { + mm_atomic.AddUint64(&mmList.beforeListCounter, 1) + defer mm_atomic.AddUint64(&mmList.afterListCounter, 1) + + mmList.t.Helper() + + if mmList.inspectFuncList != nil { + mmList.inspectFuncList(ctx, offset, limit) + } + + mm_params := NoteServiceMockListParams{ctx, offset, limit} + + // Record call args + mmList.ListMock.mutex.Lock() + mmList.ListMock.callArgs = append(mmList.ListMock.callArgs, &mm_params) + mmList.ListMock.mutex.Unlock() + + for _, e := range mmList.ListMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.npa1, e.results.err + } + } + + if mmList.ListMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmList.ListMock.defaultExpectation.Counter, 1) + mm_want := mmList.ListMock.defaultExpectation.params + mm_want_ptrs := mmList.ListMock.defaultExpectation.paramPtrs + + mm_got := NoteServiceMockListParams{ctx, offset, limit} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmList.t.Errorf("NoteServiceMock.List got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.offset != nil && !minimock.Equal(*mm_want_ptrs.offset, mm_got.offset) { + mmList.t.Errorf("NoteServiceMock.List got unexpected parameter offset, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.originOffset, *mm_want_ptrs.offset, mm_got.offset, minimock.Diff(*mm_want_ptrs.offset, mm_got.offset)) + } + + if mm_want_ptrs.limit != nil && !minimock.Equal(*mm_want_ptrs.limit, mm_got.limit) { + mmList.t.Errorf("NoteServiceMock.List got unexpected parameter limit, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.originLimit, *mm_want_ptrs.limit, mm_got.limit, minimock.Diff(*mm_want_ptrs.limit, mm_got.limit)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmList.t.Errorf("NoteServiceMock.List got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmList.ListMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmList.ListMock.defaultExpectation.results + if mm_results == nil { + mmList.t.Fatal("No results are set for the NoteServiceMock.List") + } + return (*mm_results).npa1, (*mm_results).err + } + if mmList.funcList != nil { + return mmList.funcList(ctx, offset, limit) + } + mmList.t.Fatalf("Unexpected call to NoteServiceMock.List. %v %v %v", ctx, offset, limit) + return +} + +// ListAfterCounter returns a count of finished NoteServiceMock.List invocations +func (mmList *NoteServiceMock) ListAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmList.afterListCounter) +} + +// ListBeforeCounter returns a count of NoteServiceMock.List invocations +func (mmList *NoteServiceMock) ListBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmList.beforeListCounter) +} + +// Calls returns a list of arguments used in each call to NoteServiceMock.List. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmList *mNoteServiceMockList) Calls() []*NoteServiceMockListParams { + mmList.mutex.RLock() + + argCopy := make([]*NoteServiceMockListParams, len(mmList.callArgs)) + copy(argCopy, mmList.callArgs) + + mmList.mutex.RUnlock() + + return argCopy +} + +// MinimockListDone returns true if the count of the List invocations corresponds +// the number of defined expectations +func (m *NoteServiceMock) MinimockListDone() bool { + if m.ListMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.ListMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.ListMock.invocationsDone() +} + +// MinimockListInspect logs each unmet expectation +func (m *NoteServiceMock) MinimockListInspect() { + for _, e := range m.ListMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteServiceMock.List at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterListCounter := mm_atomic.LoadUint64(&m.afterListCounter) + // if default expectation was set then invocations count should be greater than zero + if m.ListMock.defaultExpectation != nil && afterListCounter < 1 { + if m.ListMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteServiceMock.List at\n%s", m.ListMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteServiceMock.List at\n%s with params: %#v", m.ListMock.defaultExpectation.expectationOrigins.origin, *m.ListMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcList != nil && afterListCounter < 1 { + m.t.Errorf("Expected call to NoteServiceMock.List at\n%s", m.funcListOrigin) + } + + if !m.ListMock.invocationsDone() && afterListCounter > 0 { + m.t.Errorf("Expected %d calls to NoteServiceMock.List at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.ListMock.expectedInvocations), m.ListMock.expectedInvocationsOrigin, afterListCounter) + } +} + +type mNoteServiceMockUpdate struct { + optional bool + mock *NoteServiceMock + defaultExpectation *NoteServiceMockUpdateExpectation + expectations []*NoteServiceMockUpdateExpectation + + callArgs []*NoteServiceMockUpdateParams + mutex sync.RWMutex + + expectedInvocations uint64 + expectedInvocationsOrigin string +} + +// NoteServiceMockUpdateExpectation specifies expectation struct of the NoteService.Update +type NoteServiceMockUpdateExpectation struct { + mock *NoteServiceMock + params *NoteServiceMockUpdateParams + paramPtrs *NoteServiceMockUpdateParamPtrs + expectationOrigins NoteServiceMockUpdateExpectationOrigins + results *NoteServiceMockUpdateResults + returnOrigin string + Counter uint64 +} + +// NoteServiceMockUpdateParams contains parameters of the NoteService.Update +type NoteServiceMockUpdateParams struct { + ctx context.Context + info *model.UpdateNote +} + +// NoteServiceMockUpdateParamPtrs contains pointers to parameters of the NoteService.Update +type NoteServiceMockUpdateParamPtrs struct { + ctx *context.Context + info **model.UpdateNote +} + +// NoteServiceMockUpdateResults contains results of the NoteService.Update +type NoteServiceMockUpdateResults struct { + err error +} + +// NoteServiceMockUpdateOrigins contains origins of expectations of the NoteService.Update +type NoteServiceMockUpdateExpectationOrigins struct { + origin string + originCtx string + originInfo string +} + +// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning +// the test will fail minimock's automatic final call check if the mocked method was not called at least once. +// Optional() makes method check to work in '0 or more' mode. +// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to +// catch the problems when the expected method call is totally skipped during test run. +func (mmUpdate *mNoteServiceMockUpdate) Optional() *mNoteServiceMockUpdate { + mmUpdate.optional = true + return mmUpdate +} + +// Expect sets up expected params for NoteService.Update +func (mmUpdate *mNoteServiceMockUpdate) Expect(ctx context.Context, info *model.UpdateNote) *mNoteServiceMockUpdate { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteServiceMockUpdateExpectation{} + } + + if mmUpdate.defaultExpectation.paramPtrs != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by ExpectParams functions") + } + + mmUpdate.defaultExpectation.params = &NoteServiceMockUpdateParams{ctx, info} + mmUpdate.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1) + for _, e := range mmUpdate.expectations { + if minimock.Equal(e.params, mmUpdate.defaultExpectation.params) { + mmUpdate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdate.defaultExpectation.params) + } + } + + return mmUpdate +} + +// ExpectCtxParam1 sets up expected param ctx for NoteService.Update +func (mmUpdate *mNoteServiceMockUpdate) ExpectCtxParam1(ctx context.Context) *mNoteServiceMockUpdate { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteServiceMockUpdateExpectation{} + } + + if mmUpdate.defaultExpectation.params != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Expect") + } + + if mmUpdate.defaultExpectation.paramPtrs == nil { + mmUpdate.defaultExpectation.paramPtrs = &NoteServiceMockUpdateParamPtrs{} + } + mmUpdate.defaultExpectation.paramPtrs.ctx = &ctx + mmUpdate.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1) + + return mmUpdate +} + +// ExpectInfoParam2 sets up expected param info for NoteService.Update +func (mmUpdate *mNoteServiceMockUpdate) ExpectInfoParam2(info *model.UpdateNote) *mNoteServiceMockUpdate { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteServiceMockUpdateExpectation{} + } + + if mmUpdate.defaultExpectation.params != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Expect") + } + + if mmUpdate.defaultExpectation.paramPtrs == nil { + mmUpdate.defaultExpectation.paramPtrs = &NoteServiceMockUpdateParamPtrs{} + } + mmUpdate.defaultExpectation.paramPtrs.info = &info + mmUpdate.defaultExpectation.expectationOrigins.originInfo = minimock.CallerInfo(1) + + return mmUpdate +} + +// Inspect accepts an inspector function that has same arguments as the NoteService.Update +func (mmUpdate *mNoteServiceMockUpdate) Inspect(f func(ctx context.Context, info *model.UpdateNote)) *mNoteServiceMockUpdate { + if mmUpdate.mock.inspectFuncUpdate != nil { + mmUpdate.mock.t.Fatalf("Inspect function is already set for NoteServiceMock.Update") + } + + mmUpdate.mock.inspectFuncUpdate = f + + return mmUpdate +} + +// Return sets up results that will be returned by NoteService.Update +func (mmUpdate *mNoteServiceMockUpdate) Return(err error) *NoteServiceMock { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Set") + } + + if mmUpdate.defaultExpectation == nil { + mmUpdate.defaultExpectation = &NoteServiceMockUpdateExpectation{mock: mmUpdate.mock} + } + mmUpdate.defaultExpectation.results = &NoteServiceMockUpdateResults{err} + mmUpdate.defaultExpectation.returnOrigin = minimock.CallerInfo(1) + return mmUpdate.mock +} + +// Set uses given function f to mock the NoteService.Update method +func (mmUpdate *mNoteServiceMockUpdate) Set(f func(ctx context.Context, info *model.UpdateNote) (err error)) *NoteServiceMock { + if mmUpdate.defaultExpectation != nil { + mmUpdate.mock.t.Fatalf("Default expectation is already set for the NoteService.Update method") + } + + if len(mmUpdate.expectations) > 0 { + mmUpdate.mock.t.Fatalf("Some expectations are already set for the NoteService.Update method") + } + + mmUpdate.mock.funcUpdate = f + mmUpdate.mock.funcUpdateOrigin = minimock.CallerInfo(1) + return mmUpdate.mock +} + +// When sets expectation for the NoteService.Update which will trigger the result defined by the following +// Then helper +func (mmUpdate *mNoteServiceMockUpdate) When(ctx context.Context, info *model.UpdateNote) *NoteServiceMockUpdateExpectation { + if mmUpdate.mock.funcUpdate != nil { + mmUpdate.mock.t.Fatalf("NoteServiceMock.Update mock is already set by Set") + } + + expectation := &NoteServiceMockUpdateExpectation{ + mock: mmUpdate.mock, + params: &NoteServiceMockUpdateParams{ctx, info}, + expectationOrigins: NoteServiceMockUpdateExpectationOrigins{origin: minimock.CallerInfo(1)}, + } + mmUpdate.expectations = append(mmUpdate.expectations, expectation) + return expectation +} + +// Then sets up NoteService.Update return parameters for the expectation previously defined by the When method +func (e *NoteServiceMockUpdateExpectation) Then(err error) *NoteServiceMock { + e.results = &NoteServiceMockUpdateResults{err} + return e.mock +} + +// Times sets number of times NoteService.Update should be invoked +func (mmUpdate *mNoteServiceMockUpdate) Times(n uint64) *mNoteServiceMockUpdate { + if n == 0 { + mmUpdate.mock.t.Fatalf("Times of NoteServiceMock.Update mock can not be zero") + } + mm_atomic.StoreUint64(&mmUpdate.expectedInvocations, n) + mmUpdate.expectedInvocationsOrigin = minimock.CallerInfo(1) + return mmUpdate +} + +func (mmUpdate *mNoteServiceMockUpdate) invocationsDone() bool { + if len(mmUpdate.expectations) == 0 && mmUpdate.defaultExpectation == nil && mmUpdate.mock.funcUpdate == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmUpdate.mock.afterUpdateCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmUpdate.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// Update implements mm_service.NoteService +func (mmUpdate *NoteServiceMock) Update(ctx context.Context, info *model.UpdateNote) (err error) { + mm_atomic.AddUint64(&mmUpdate.beforeUpdateCounter, 1) + defer mm_atomic.AddUint64(&mmUpdate.afterUpdateCounter, 1) + + mmUpdate.t.Helper() + + if mmUpdate.inspectFuncUpdate != nil { + mmUpdate.inspectFuncUpdate(ctx, info) + } + + mm_params := NoteServiceMockUpdateParams{ctx, info} + + // Record call args + mmUpdate.UpdateMock.mutex.Lock() + mmUpdate.UpdateMock.callArgs = append(mmUpdate.UpdateMock.callArgs, &mm_params) + mmUpdate.UpdateMock.mutex.Unlock() + + for _, e := range mmUpdate.UpdateMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmUpdate.UpdateMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmUpdate.UpdateMock.defaultExpectation.Counter, 1) + mm_want := mmUpdate.UpdateMock.defaultExpectation.params + mm_want_ptrs := mmUpdate.UpdateMock.defaultExpectation.paramPtrs + + mm_got := NoteServiceMockUpdateParams{ctx, info} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmUpdate.t.Errorf("NoteServiceMock.Update got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmUpdate.UpdateMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.info != nil && !minimock.Equal(*mm_want_ptrs.info, mm_got.info) { + mmUpdate.t.Errorf("NoteServiceMock.Update got unexpected parameter info, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmUpdate.UpdateMock.defaultExpectation.expectationOrigins.originInfo, *mm_want_ptrs.info, mm_got.info, minimock.Diff(*mm_want_ptrs.info, mm_got.info)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmUpdate.t.Errorf("NoteServiceMock.Update got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n", + mmUpdate.UpdateMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmUpdate.UpdateMock.defaultExpectation.results + if mm_results == nil { + mmUpdate.t.Fatal("No results are set for the NoteServiceMock.Update") + } + return (*mm_results).err + } + if mmUpdate.funcUpdate != nil { + return mmUpdate.funcUpdate(ctx, info) + } + mmUpdate.t.Fatalf("Unexpected call to NoteServiceMock.Update. %v %v", ctx, info) + return +} + +// UpdateAfterCounter returns a count of finished NoteServiceMock.Update invocations +func (mmUpdate *NoteServiceMock) UpdateAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdate.afterUpdateCounter) +} + +// UpdateBeforeCounter returns a count of NoteServiceMock.Update invocations +func (mmUpdate *NoteServiceMock) UpdateBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdate.beforeUpdateCounter) +} + +// Calls returns a list of arguments used in each call to NoteServiceMock.Update. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmUpdate *mNoteServiceMockUpdate) Calls() []*NoteServiceMockUpdateParams { + mmUpdate.mutex.RLock() + + argCopy := make([]*NoteServiceMockUpdateParams, len(mmUpdate.callArgs)) + copy(argCopy, mmUpdate.callArgs) + + mmUpdate.mutex.RUnlock() + + return argCopy +} + +// MinimockUpdateDone returns true if the count of the Update invocations corresponds +// the number of defined expectations +func (m *NoteServiceMock) MinimockUpdateDone() bool { + if m.UpdateMock.optional { + // Optional methods provide '0 or more' call count restriction. + return true + } + + for _, e := range m.UpdateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.UpdateMock.invocationsDone() +} + +// MinimockUpdateInspect logs each unmet expectation +func (m *NoteServiceMock) MinimockUpdateInspect() { + for _, e := range m.UpdateMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Update at\n%s with params: %#v", e.expectationOrigins.origin, *e.params) + } + } + + afterUpdateCounter := mm_atomic.LoadUint64(&m.afterUpdateCounter) + // if default expectation was set then invocations count should be greater than zero + if m.UpdateMock.defaultExpectation != nil && afterUpdateCounter < 1 { + if m.UpdateMock.defaultExpectation.params == nil { + m.t.Errorf("Expected call to NoteServiceMock.Update at\n%s", m.UpdateMock.defaultExpectation.returnOrigin) + } else { + m.t.Errorf("Expected call to NoteServiceMock.Update at\n%s with params: %#v", m.UpdateMock.defaultExpectation.expectationOrigins.origin, *m.UpdateMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcUpdate != nil && afterUpdateCounter < 1 { + m.t.Errorf("Expected call to NoteServiceMock.Update at\n%s", m.funcUpdateOrigin) + } + + if !m.UpdateMock.invocationsDone() && afterUpdateCounter > 0 { + m.t.Errorf("Expected %d calls to NoteServiceMock.Update at\n%s but found %d calls", + mm_atomic.LoadUint64(&m.UpdateMock.expectedInvocations), m.UpdateMock.expectedInvocationsOrigin, afterUpdateCounter) + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *NoteServiceMock) MinimockFinish() { + m.finishOnce.Do(func() { + if !m.minimockDone() { + m.MinimockCreateInspect() + + m.MinimockDeleteInspect() + + m.MinimockGetInspect() + + m.MinimockListInspect() + + m.MinimockUpdateInspect() + } + }) +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *NoteServiceMock) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *NoteServiceMock) minimockDone() bool { + done := true + return done && + m.MinimockCreateDone() && + m.MinimockDeleteDone() && + m.MinimockGetDone() && + m.MinimockListDone() && + m.MinimockUpdateDone() +} diff --git a/internal/service/tests/create_test.go b/internal/service/tests/create_test.go new file mode 100644 index 0000000..beaa44c --- /dev/null +++ b/internal/service/tests/create_test.go @@ -0,0 +1,94 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/repository" + repositoryMocks "github.com/xeeetu/gRPC/internal/repository/mocks" + noteService "github.com/xeeetu/gRPC/internal/service/note" + "github.com/xeeetu/gRPC/model" +) + +func TestCreate(t *testing.T) { + //t.Parallel() + type noteRepositoryMockFunc func(mc *minimock.Controller) repository.NoteRepository + + type args struct { + ctx context.Context + modelInfo *model.NoteInfo + } + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + id = gofakeit.Int64() + title = gofakeit.Name() + content = gofakeit.Name() + + repoErr = fmt.Errorf("repository error") + repoErrInServ = fmt.Errorf("s.noteRepository.Create: %w", repoErr) + + modelInfo = &model.NoteInfo{ + Title: title, + Content: content, + } + ) + + tests := []struct { + name string + args args + want int64 + err error + noteRepositoryMockFunc noteRepositoryMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + modelInfo: modelInfo, + }, + want: id, + err: nil, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.CreateMock.Expect(ctx, modelInfo).Return(id, nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + modelInfo: modelInfo, + }, + want: 0, + err: repoErrInServ, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.CreateMock.Expect(ctx, modelInfo).Return(0, repoErr) + return mock + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + //t.Parallel() + + mock := tt.noteRepositoryMockFunc(mc) + serv := noteService.NewService(mock) + + resHandler, err := serv.Create(tt.args.ctx, tt.args.modelInfo) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/service/tests/delete_test.go b/internal/service/tests/delete_test.go new file mode 100644 index 0000000..ece680b --- /dev/null +++ b/internal/service/tests/delete_test.go @@ -0,0 +1,82 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/repository" + repositoryMocks "github.com/xeeetu/gRPC/internal/repository/mocks" + noteService "github.com/xeeetu/gRPC/internal/service/note" +) + +func TestDelete(t *testing.T) { + //t.Parallel() + type noteRepositoryMockFunc func(mc *minimock.Controller) repository.NoteRepository + + type args struct { + ctx context.Context + id int64 + } + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + id = gofakeit.Int64() + + repoErr = fmt.Errorf("repository error") + repoErrInServ = fmt.Errorf("s.noteRepository.Delete: %w", repoErr) + ) + + tests := []struct { + name string + args args + err error + noteRepositoryMockFunc noteRepositoryMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + id: id, + }, + err: nil, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.DeleteMock.Expect(ctx, id).Return(nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + id: id, + }, + err: repoErrInServ, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.DeleteMock.Expect(ctx, id).Return(repoErr) + return mock + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + //t.Parallel() + + mock := tt.noteRepositoryMockFunc(mc) + serv := noteService.NewService(mock) + + err := serv.Delete(tt.args.ctx, tt.args.id) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/service/tests/get_test.go b/internal/service/tests/get_test.go new file mode 100644 index 0000000..aefe8fc --- /dev/null +++ b/internal/service/tests/get_test.go @@ -0,0 +1,107 @@ +package tests + +import ( + "context" + "database/sql" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/repository" + repositoryMocks "github.com/xeeetu/gRPC/internal/repository/mocks" + noteService "github.com/xeeetu/gRPC/internal/service/note" + "github.com/xeeetu/gRPC/model" +) + +func TestGet(t *testing.T) { + //t.Parallel() + type noteRepositoryMockFunc func(mc *minimock.Controller) repository.NoteRepository + + type args struct { + ctx context.Context + id int64 + } + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + id = gofakeit.Int64() + title = gofakeit.Name() + content = gofakeit.Name() + createdAt = gofakeit.Date() + updatedAt = gofakeit.Date() + + repoErr = fmt.Errorf("repository error") + repoErrInServ = fmt.Errorf("s.noteRepository.Get: %w", repoErr) + + modelInfo = model.NoteInfo{ + Title: title, + Content: content, + } + + modelNote = &model.Note{ + ID: id, + Info: modelInfo, + CreatedAt: createdAt, + UpdatedAt: sql.NullTime{ + Time: updatedAt, + Valid: true, + }, + } + ) + + tests := []struct { + name string + args args + want *model.Note + err error + noteRepositoryMockFunc noteRepositoryMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + id: id, + }, + want: modelNote, + err: nil, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.GetMock.Expect(ctx, id).Return(modelNote, nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + id: id, + }, + want: nil, + err: repoErrInServ, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.GetMock.Expect(ctx, id).Return(nil, repoErr) + return mock + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + //t.Parallel() + + mock := tt.noteRepositoryMockFunc(mc) + serv := noteService.NewService(mock) + + resHandler, err := serv.Get(tt.args.ctx, tt.args.id) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/service/tests/list_test.go b/internal/service/tests/list_test.go new file mode 100644 index 0000000..068d3a2 --- /dev/null +++ b/internal/service/tests/list_test.go @@ -0,0 +1,113 @@ +package tests + +import ( + "context" + "database/sql" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/repository" + repositoryMocks "github.com/xeeetu/gRPC/internal/repository/mocks" + noteService "github.com/xeeetu/gRPC/internal/service/note" + "github.com/xeeetu/gRPC/model" +) + +func TestList(t *testing.T) { + //t.Parallel() + type noteRepositoryMockFunc func(mc *minimock.Controller) repository.NoteRepository + + type args struct { + ctx context.Context + offset, limit int64 + } + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + id = gofakeit.Int64() + offset = int64(gofakeit.Number(0, 10)) + limit = int64(gofakeit.Number(1, 10)) + title = gofakeit.Name() + content = gofakeit.Name() + createdAt = gofakeit.Date() + updatedAt = gofakeit.Date() + + repoErr = fmt.Errorf("repository error") + repoErrInServ = fmt.Errorf("s.noteRepository.List: %w", repoErr) + + modelInfo = model.NoteInfo{ + Title: title, + Content: content, + } + + modelNote = &model.Note{ + ID: id, + Info: modelInfo, + CreatedAt: createdAt, + UpdatedAt: sql.NullTime{ + Time: updatedAt, + Valid: true, + }, + } + + modelNotes = []*model.Note{modelNote} + ) + + tests := []struct { + name string + args args + want []*model.Note + err error + noteRepositoryMockFunc noteRepositoryMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + offset: offset, + limit: limit, + }, + want: modelNotes, + err: nil, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.ListMock.Expect(ctx, offset, limit).Return(modelNotes, nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + offset: offset, + limit: limit, + }, + want: nil, + err: repoErrInServ, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.ListMock.Expect(ctx, offset, limit).Return(nil, repoErr) + return mock + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + //t.Parallel() + + mock := tt.noteRepositoryMockFunc(mc) + serv := noteService.NewService(mock) + + resHandler, err := serv.List(tt.args.ctx, tt.args.offset, tt.args.limit) + require.Equal(t, tt.want, resHandler) + require.Equal(t, tt.err, err) + }) + } +} diff --git a/internal/service/tests/update_test.go b/internal/service/tests/update_test.go new file mode 100644 index 0000000..bf46f15 --- /dev/null +++ b/internal/service/tests/update_test.go @@ -0,0 +1,95 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v7" + "github.com/gojuno/minimock/v3" + "github.com/stretchr/testify/require" + "github.com/xeeetu/gRPC/internal/repository" + repositoryMocks "github.com/xeeetu/gRPC/internal/repository/mocks" + noteService "github.com/xeeetu/gRPC/internal/service/note" + "github.com/xeeetu/gRPC/model" +) + +func TestUpdate(t *testing.T) { + //t.Parallel() + type noteRepositoryMockFunc func(mc *minimock.Controller) repository.NoteRepository + + type args struct { + ctx context.Context + updateNote *model.UpdateNote + } + var ( + ctx = context.Background() + mc = minimock.NewController(t) + + id = gofakeit.Int64() + title = gofakeit.Name() + content = gofakeit.Name() + + repoErr = fmt.Errorf("repository error") + repoErrInServ = fmt.Errorf("s.noteRepository.Update: %w", repoErr) + + modelUpdateInfo = &model.UpdateNoteInfo{ + Title: &title, + Content: &content, + } + + modelUpdateNote = &model.UpdateNote{ + ID: id, + Info: modelUpdateInfo, + } + ) + + tests := []struct { + name string + args args + err error + noteRepositoryMockFunc noteRepositoryMockFunc + }{ + { + name: "success case", + args: args{ + ctx: ctx, + updateNote: modelUpdateNote, + }, + err: nil, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.UpdateMock.Expect(ctx, modelUpdateNote).Return(nil) + return mock + }, + }, + { + name: "service error case", + args: args{ + ctx: ctx, + updateNote: modelUpdateNote, + }, + err: repoErrInServ, + noteRepositoryMockFunc: func(mc *minimock.Controller) repository.NoteRepository { + mock := repositoryMocks.NewNoteRepositoryMock(mc) + + mock.UpdateMock.Expect(ctx, modelUpdateNote).Return(repoErr) + return mock + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + //t.Parallel() + + mock := tt.noteRepositoryMockFunc(mc) + serv := noteService.NewService(mock) + + err := serv.Update(tt.args.ctx, tt.args.updateNote) + require.Equal(t, tt.err, err) + }) + } +}