Skip to content

Commit

Permalink
Fixed issue w/ reused structs
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisoncramer committed Sep 16, 2024
1 parent 7b5d1cb commit f95e2a3
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 103 deletions.
6 changes: 3 additions & 3 deletions cmd/app/assignee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAssigneeHandler(t *testing.T) {
svc := middleware(
assigneesService{testProjectData, fakeAssigneeClient{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
withMethodCheck(http.MethodPut),
)
data := getSuccessData(t, svc, request)
Expand All @@ -40,7 +40,7 @@ func TestAssigneeHandler(t *testing.T) {
svc := middleware(
assigneesService{testProjectData, client},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
withMethodCheck(http.MethodPut),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -53,7 +53,7 @@ func TestAssigneeHandler(t *testing.T) {
svc := middleware(
assigneesService{testProjectData, client},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
withMethodCheck(http.MethodPut),
)
data, _ := getFailData(t, svc, request)
Expand Down
6 changes: 3 additions & 3 deletions cmd/app/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestAttachmentHandler(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
svc := middleware(
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{}},
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
withMethodCheck(http.MethodPost),
)
data := getSuccessData(t, svc, request)
Expand All @@ -49,7 +49,7 @@ func TestAttachmentHandler(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
svc := middleware(
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{testBase{errFromGitlab: true}}},
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -60,7 +60,7 @@ func TestAttachmentHandler(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
svc := middleware(
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{testBase{status: http.StatusSeeOther}}},
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand Down
36 changes: 18 additions & 18 deletions cmd/app/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func TestPostComment(t *testing.T) {
commentService{testProjectData, fakeCommentClient{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostCommentRequest{},
http.MethodDelete: &DeleteCommentRequest{},
http.MethodPatch: &EditCommentRequest{},
http.MethodPost: newPayload[PostCommentRequest],
http.MethodDelete: newPayload[DeleteCommentRequest],
http.MethodPatch: newPayload[EditCommentRequest],
}),
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
)
Expand All @@ -66,9 +66,9 @@ func TestPostComment(t *testing.T) {
commentService{testProjectData, fakeCommentClient{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostCommentRequest{},
http.MethodDelete: &DeleteCommentRequest{},
http.MethodPatch: &EditCommentRequest{},
http.MethodPost: newPayload[PostCommentRequest],
http.MethodDelete: newPayload[DeleteCommentRequest],
http.MethodPatch: newPayload[EditCommentRequest],
}),
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
)
Expand All @@ -82,9 +82,9 @@ func TestPostComment(t *testing.T) {
commentService{testProjectData, fakeCommentClient{testBase{errFromGitlab: true}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostCommentRequest{},
http.MethodDelete: &DeleteCommentRequest{},
http.MethodPatch: &EditCommentRequest{},
http.MethodPost: newPayload[PostCommentRequest],
http.MethodDelete: newPayload[DeleteCommentRequest],
http.MethodPatch: newPayload[EditCommentRequest],
}),
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
)
Expand All @@ -98,9 +98,9 @@ func TestPostComment(t *testing.T) {
commentService{testProjectData, fakeCommentClient{testBase{status: http.StatusSeeOther}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostCommentRequest{},
http.MethodDelete: &DeleteCommentRequest{},
http.MethodPatch: &EditCommentRequest{},
http.MethodPost: newPayload[PostCommentRequest],
http.MethodDelete: newPayload[DeleteCommentRequest],
http.MethodPatch: newPayload[EditCommentRequest],
}),
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
)
Expand All @@ -117,9 +117,9 @@ func TestDeleteComment(t *testing.T) {
commentService{testProjectData, fakeCommentClient{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostCommentRequest{},
http.MethodDelete: &DeleteCommentRequest{},
http.MethodPatch: &EditCommentRequest{},
http.MethodPost: newPayload[PostCommentRequest],
http.MethodDelete: newPayload[DeleteCommentRequest],
http.MethodPatch: newPayload[EditCommentRequest],
}),
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
)
Expand All @@ -136,9 +136,9 @@ func TestEditComment(t *testing.T) {
commentService{testProjectData, fakeCommentClient{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostCommentRequest{},
http.MethodDelete: &DeleteCommentRequest{},
http.MethodPatch: &EditCommentRequest{},
http.MethodPost: newPayload[PostCommentRequest],
http.MethodDelete: newPayload[DeleteCommentRequest],
http.MethodPatch: newPayload[EditCommentRequest],
}),
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
)
Expand Down
10 changes: 5 additions & 5 deletions cmd/app/create_mr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestCreateMr(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
svc := middleware(
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
withMethodCheck(http.MethodPost),
)
data := getSuccessData(t, svc, request)
Expand All @@ -42,7 +42,7 @@ func TestCreateMr(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
svc := middleware(
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{testBase{errFromGitlab: true}}},
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -53,7 +53,7 @@ func TestCreateMr(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
svc := middleware(
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{testBase{status: http.StatusSeeOther}}},
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -66,7 +66,7 @@ func TestCreateMr(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/create_mr", reqData)
svc := middleware(
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -80,7 +80,7 @@ func TestCreateMr(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/create_mr", reqData)
svc := middleware(
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand Down
8 changes: 4 additions & 4 deletions cmd/app/draft_note_publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestPublishDraftNote(t *testing.T) {
svc := middleware(
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
withMethodCheck(http.MethodPost),
)
data := getSuccessData(t, svc, request)
Expand All @@ -36,7 +36,7 @@ func TestPublishDraftNote(t *testing.T) {
svc := middleware(
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{testBase: testBase{errFromGitlab: true}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -51,7 +51,7 @@ func TestPublishAllDraftNotes(t *testing.T) {
svc := middleware(
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
withMethodCheck(http.MethodPost),
)
data := getSuccessData(t, svc, request)
Expand All @@ -62,7 +62,7 @@ func TestPublishAllDraftNotes(t *testing.T) {
svc := middleware(
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{testBase: testBase{errFromGitlab: true}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand Down
36 changes: 18 additions & 18 deletions cmd/app/draft_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestListDraftNotes(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -61,8 +61,8 @@ func TestListDraftNotes(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{testBase: testBase{errFromGitlab: true}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -75,8 +75,8 @@ func TestListDraftNotes(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{testBase: testBase{status: http.StatusSeeOther}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -96,8 +96,8 @@ func TestPostDraftNote(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -113,8 +113,8 @@ func TestDeleteDraftNote(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -127,8 +127,8 @@ func TestDeleteDraftNote(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -146,8 +146,8 @@ func TestEditDraftNote(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -160,8 +160,8 @@ func TestEditDraftNote(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand All @@ -177,8 +177,8 @@ func TestEditDraftNote(t *testing.T) {
draftNoteService{testProjectData, fakeDraftNoteManager{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{
http.MethodPost: &PostDraftNoteRequest{},
http.MethodPatch: &UpdateDraftNoteRequest{},
http.MethodPost: newPayload[PostDraftNoteRequest],
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
}),
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
)
Expand Down
6 changes: 3 additions & 3 deletions cmd/app/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestJobHandler(t *testing.T) {
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 3})
svc := middleware(
traceFileService{testProjectData, fakeTraceFileGetter{}},
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
withMethodCheck(http.MethodGet),
)
data := getTraceFileData(t, svc, request)
Expand All @@ -51,7 +51,7 @@ func TestJobHandler(t *testing.T) {
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 2})
svc := middleware(
traceFileService{testProjectData, fakeTraceFileGetter{testBase{errFromGitlab: true}}},
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
withMethodCheck(http.MethodGet),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -62,7 +62,7 @@ func TestJobHandler(t *testing.T) {
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 1})
svc := middleware(
traceFileService{testProjectData, fakeTraceFileGetter{testBase{status: http.StatusSeeOther}}},
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
withMethodCheck(http.MethodGet),
)
data, _ := getFailData(t, svc, request)
Expand Down
10 changes: 5 additions & 5 deletions cmd/app/list_discussions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestListDiscussions(t *testing.T) {
svc := middleware(
discussionsListerService{testProjectData, fakeDiscussionsLister{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
withMethodCheck(http.MethodPost),
)
data := getDiscussionsList(t, svc, request)
Expand All @@ -85,7 +85,7 @@ func TestListDiscussions(t *testing.T) {
svc := middleware(
discussionsListerService{testProjectData, fakeDiscussionsLister{}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
withMethodCheck(http.MethodPost),
)
data := getDiscussionsList(t, svc, request)
Expand All @@ -98,7 +98,7 @@ func TestListDiscussions(t *testing.T) {
svc := middleware(
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{errFromGitlab: true}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -109,7 +109,7 @@ func TestListDiscussions(t *testing.T) {
svc := middleware(
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{status: http.StatusSeeOther}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand All @@ -120,7 +120,7 @@ func TestListDiscussions(t *testing.T) {
svc := middleware(
discussionsListerService{testProjectData, fakeDiscussionsLister{badEmojiResponse: true, testBase: testBase{}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
Expand Down
Loading

0 comments on commit f95e2a3

Please sign in to comment.