From bd9e1d48c8159b8bd3230cf3c006aea87fd97249 Mon Sep 17 00:00:00 2001 From: Alexeyzem Date: Thu, 12 Dec 2024 17:34:46 +0300 Subject: [PATCH] hotfix tests --- internal/post/controller/controller_test.go | 1230 +++++++++++-------- 1 file changed, 705 insertions(+), 525 deletions(-) diff --git a/internal/post/controller/controller_test.go b/internal/post/controller/controller_test.go index 4edb1345..ed2e5360 100644 --- a/internal/post/controller/controller_test.go +++ b/internal/post/controller/controller_test.go @@ -18,11 +18,12 @@ import ( func getController(ctrl *gomock.Controller) (*PostController, *mocks) { m := &mocks{ - postService: NewMockPostService(ctrl), - responder: NewMockResponder(ctrl), + postService: NewMockPostService(ctrl), + responder: NewMockResponder(ctrl), + CommentService: NewMockCommentService(ctrl), } - return NewPostController(m.postService, m.responder), m + return NewPostController(m.postService, m.CommentService, m.responder), m } func TestNewPostController(t *testing.T) { @@ -53,19 +54,23 @@ func TestCreate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "2", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() res := &Request{r: req, w: w} return res, nil @@ -81,19 +86,23 @@ func TestCreate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "3", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -111,19 +120,23 @@ func TestCreate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().Create(gomock.Any(), gomock.Any()).Return(uint32(0), errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "4", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -141,19 +154,23 @@ func TestCreate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().Create(gomock.Any(), gomock.Any()).Return(uint32(2), nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, data, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, data, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "5", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed?community=ljkhkg", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed?community=ljkhkg", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -170,19 +187,23 @@ func TestCreate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "6", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed?community=10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed?community=10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -200,19 +221,23 @@ func TestCreate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(false) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "7", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed?community=10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed?community=10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -230,20 +255,26 @@ func TestCreate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) - m.postService.EXPECT().CreateCommunityPost(gomock.Any(), gomock.Any()).Return(uint32(0), errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().CreateCommunityPost(gomock.Any(), gomock.Any()).Return( + uint32(0), errors.New("error"), + ) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "8", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed?community=10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed?community=10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -262,19 +293,23 @@ func TestCreate(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) m.postService.EXPECT().CreateCommunityPost(gomock.Any(), gomock.Any()).Return(uint32(10), nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, data, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, data, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "9", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPost, "/api/v1/feed?community=10", - bytes.NewBuffer([]byte(`{"post_content":{"text":"new post Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tellus arcu, vulputate rutrum enim vitae, tincidunt imperdiet tellus. Aenean vulputate elit consequat lorem pellentesque bibendum. Donec sed mi posuere dolor semper mollis eu eget dolor. Proin et eleifend magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur tempus ultricies mi, eget malesuada metus. Nam sit amet felis nec dolor vehicula dapibus gravida in nunc. Mauris turpis et. "}}`))) + req := httptest.NewRequest( + http.MethodPost, "/api/v1/feed?community=10", + bytes.NewBuffer([]byte(`{"post_content":{"text":"new post Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tellus arcu, vulputate rutrum enim vitae, tincidunt imperdiet tellus. Aenean vulputate elit consequat lorem pellentesque bibendum. Donec sed mi posuere dolor semper mollis eu eget dolor. Proin et eleifend magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur tempus ultricies mi, eget malesuada metus. Nam sit amet felis nec dolor vehicula dapibus gravida in nunc. Mauris turpis et. "}}`)), + ) w := httptest.NewRecorder() req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) res := &Request{r: req, w: w} @@ -291,42 +326,46 @@ func TestCreate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, data, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, data, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } @@ -351,12 +390,14 @@ func TestGetOne(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -379,12 +420,14 @@ func TestGetOne(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -409,12 +452,14 @@ func TestGetOne(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, my_err.ErrPostNotFound) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -439,12 +484,14 @@ func TestGetOne(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -469,12 +516,14 @@ func TestGetOne(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -497,42 +546,46 @@ func TestGetOne(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } @@ -556,12 +609,14 @@ func TestUpdate(t *testing.T) { }, ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -584,12 +639,14 @@ func TestUpdate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -613,13 +670,17 @@ func TestUpdate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(0), errors.New("error")) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return( + uint32(0), errors.New("error"), + ) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -644,19 +705,23 @@ func TestUpdate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(10), nil) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "5", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -676,19 +741,23 @@ func TestUpdate(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(1), nil) m.postService.EXPECT().Update(gomock.Any(), gomock.Any()).Return(my_err.ErrPostNotFound) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "6", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -708,19 +777,23 @@ func TestUpdate(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(1), nil) m.postService.EXPECT().Update(gomock.Any(), gomock.Any()).Return(errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "7", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -740,19 +813,23 @@ func TestUpdate(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(1), nil) m.postService.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "8", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10?community=nkljbkvhj", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10?community=nkljbkvhj", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -770,19 +847,23 @@ func TestUpdate(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "9", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10?community=10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10?community=10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -801,19 +882,23 @@ func TestUpdate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(false) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "10", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10?community=10", - bytes.NewBuffer([]byte(`{"id":1}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10?community=10", + bytes.NewBuffer([]byte(`{"id":1}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -833,19 +918,23 @@ func TestUpdate(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) m.postService.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "11", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10?community=10", - bytes.NewBuffer([]byte(`{"id"`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10?community=10", + bytes.NewBuffer([]byte(`{"id"`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -864,19 +953,23 @@ func TestUpdate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { name: "12", SetupInput: func() (*Request, error) { - req := httptest.NewRequest(http.MethodPut, "/api/v1/feed/10?community=1", - bytes.NewBuffer([]byte(`{"post_content":{"text":"new post Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tellus arcu, vulputate rutrum enim vitae, tincidunt imperdiet tellus. Aenean vulputate elit consequat lorem pellentesque bibendum. Donec sed mi posuere dolor semper mollis eu eget dolor. Proin et eleifend magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur tempus ultricies mi, eget malesuada metus. Nam sit amet felis nec dolor vehicula dapibus gravida in nunc. Mauris turpis et. "}}`))) + req := httptest.NewRequest( + http.MethodPut, "/api/v1/feed/10?community=1", + bytes.NewBuffer([]byte(`{"post_content":{"text":"new post Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tellus arcu, vulputate rutrum enim vitae, tincidunt imperdiet tellus. Aenean vulputate elit consequat lorem pellentesque bibendum. Donec sed mi posuere dolor semper mollis eu eget dolor. Proin et eleifend magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur tempus ultricies mi, eget malesuada metus. Nam sit amet felis nec dolor vehicula dapibus gravida in nunc. Mauris turpis et. "}}`)), + ) w := httptest.NewRecorder() req = mux.SetURLVars(req, map[string]string{"id": "10"}) req = req.WithContext(models.ContextWithSession(req.Context(), &models.Session{ID: "1", UserID: 1})) @@ -895,42 +988,46 @@ func TestUpdate(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } @@ -955,12 +1052,14 @@ func TestDelete(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -983,12 +1082,14 @@ func TestDelete(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1014,12 +1115,14 @@ func TestDelete(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(1), nil) m.postService.EXPECT().Delete(gomock.Any(), gomock.Any()).Return(my_err.ErrPostNotFound) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1045,12 +1148,14 @@ func TestDelete(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(1), nil) m.postService.EXPECT().Delete(gomock.Any(), gomock.Any()).Return(errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1076,12 +1181,14 @@ func TestDelete(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetPostAuthorID(gomock.Any(), gomock.Any()).Return(uint32(1), nil) m.postService.EXPECT().Delete(gomock.Any(), gomock.Any()).Return(nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, data, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, data, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1105,12 +1212,14 @@ func TestDelete(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, error, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, error, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1133,12 +1242,14 @@ func TestDelete(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, error, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, error, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1164,42 +1275,46 @@ func TestDelete(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().CheckAccessToCommunity(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) m.postService.EXPECT().Delete(gomock.Any(), gomock.Any()).Return(nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, error, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, error, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } @@ -1224,12 +1339,14 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1251,12 +1368,14 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1279,10 +1398,14 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.postService.EXPECT().GetBatch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, my_err.ErrNoMoreContent) - m.responder.EXPECT().OutputNoMoreContentJSON(request.w, gomock.Any()).Do(func(w, req any) { - request.w.WriteHeader(http.StatusNoContent) - }) + m.postService.EXPECT().GetBatch(gomock.Any(), gomock.Any(), gomock.Any()).Return( + nil, my_err.ErrNoMoreContent, + ) + m.responder.EXPECT().OutputNoMoreContentJSON(request.w, gomock.Any()).Do( + func(w, req any) { + request.w.WriteHeader(http.StatusNoContent) + }, + ) }, }, { @@ -1305,13 +1428,17 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.postService.EXPECT().GetBatch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().GetBatch(gomock.Any(), gomock.Any(), gomock.Any()).Return( + nil, errors.New("error"), + ) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1335,12 +1462,14 @@ func TestGetBatchPost(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetBatch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1362,12 +1491,14 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1392,12 +1523,14 @@ func TestGetBatchPost(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) m.postService.EXPECT().GetBatchFromFriend(gomock.Any(), gomock.Any(), gomock.Any()). Return(nil, nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1420,12 +1553,14 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1448,13 +1583,17 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.postService.EXPECT().GetCommunityPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().GetCommunityPost( + gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), + ).Return(nil, nil) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1477,42 +1616,46 @@ func TestGetBatchPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()).Do(func(err, req any) {}) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } @@ -1537,12 +1680,14 @@ func TestSetLikeOnPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1565,12 +1710,14 @@ func TestSetLikeOnPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1595,12 +1742,14 @@ func TestSetLikeOnPost(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1624,13 +1773,17 @@ func TestSetLikeOnPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return( + false, errors.New("error"), + ) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1655,13 +1808,17 @@ func TestSetLikeOnPost(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil) - m.postService.EXPECT().SetLikeToPost(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().SetLikeToPost( + gomock.Any(), gomock.Any(), gomock.Any(), + ).Return(errors.New("error")) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1687,42 +1844,46 @@ func TestSetLikeOnPost(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil) m.postService.EXPECT().SetLikeToPost(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, data, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, data, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } @@ -1747,12 +1908,14 @@ func TestDeleteLikeFromPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1775,12 +1938,14 @@ func TestDeleteLikeFromPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1805,12 +1970,14 @@ func TestDeleteLikeFromPost(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil) - m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusBadRequest) - if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().ErrorBadRequest(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusBadRequest) + if _, err1 := request.w.Write([]byte("bad request")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1834,13 +2001,17 @@ func TestDeleteLikeFromPost(t *testing.T) { ExpectedErr: nil, SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) - m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return( + false, errors.New("error"), + ) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1865,13 +2036,17 @@ func TestDeleteLikeFromPost(t *testing.T) { SetupMock: func(request Request, m *mocks) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil) - m.postService.EXPECT().DeleteLikeFromPost(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")) - m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do(func(w, err, req any) { - request.w.WriteHeader(http.StatusInternalServerError) - if _, err1 := request.w.Write([]byte("error")); err1 != nil { - panic(err1) - } - }) + m.postService.EXPECT().DeleteLikeFromPost( + gomock.Any(), gomock.Any(), gomock.Any(), + ).Return(errors.New("error")) + m.responder.EXPECT().ErrorInternal(request.w, gomock.Any(), gomock.Any()).Do( + func(w, err, req any) { + request.w.WriteHeader(http.StatusInternalServerError) + if _, err1 := request.w.Write([]byte("error")); err1 != nil { + panic(err1) + } + }, + ) }, }, { @@ -1897,48 +2072,53 @@ func TestDeleteLikeFromPost(t *testing.T) { m.responder.EXPECT().LogError(gomock.Any(), gomock.Any()) m.postService.EXPECT().CheckLikes(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil) m.postService.EXPECT().DeleteLikeFromPost(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do(func(w, data, req any) { - request.w.WriteHeader(http.StatusOK) - if _, err1 := request.w.Write([]byte("OK")); err1 != nil { - panic(err1) - } - }) + m.responder.EXPECT().OutputJSON(request.w, gomock.Any(), gomock.Any()).Do( + func(w, data, req any) { + request.w.WriteHeader(http.StatusOK) + if _, err1 := request.w.Write([]byte("OK")); err1 != nil { + panic(err1) + } + }, + ) }, }, } for _, v := range tests { - t.Run(v.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Run( + v.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serv, mock := getController(ctrl) - ctx := context.Background() + serv, mock := getController(ctrl) + ctx := context.Background() - input, err := v.SetupInput() - if err != nil { - t.Error(err) - } + input, err := v.SetupInput() + if err != nil { + t.Error(err) + } - v.SetupMock(*input, mock) + v.SetupMock(*input, mock) - res, err := v.ExpectedResult() - if err != nil { - t.Error(err) - } + res, err := v.ExpectedResult() + if err != nil { + t.Error(err) + } - actual, err := v.Run(ctx, serv, *input) - assert.Equal(t, res, actual) - if !errors.Is(err, v.ExpectedErr) { - t.Errorf("expect %v, got %v", v.ExpectedErr, err) - } - }) + actual, err := v.Run(ctx, serv, *input) + assert.Equal(t, res, actual) + if !errors.Is(err, v.ExpectedErr) { + t.Errorf("expect %v, got %v", v.ExpectedErr, err) + } + }, + ) } } type mocks struct { - postService *MockPostService - responder *MockResponder + postService *MockPostService + CommentService *MockCommentService + responder *MockResponder } type Request struct {