Content-Length: 5562 | pFad | http://github.com/github/github-mcp-server/pull/95.patch
thub.com
From 278ec38f50a2372a3886a9ddbd7eb17dcfb72a1d Mon Sep 17 00:00:00 2001
From: Javier Uruen Val
Date: Fri, 4 Apr 2025 12:10:47 +0200
Subject: [PATCH] assert request params and body
---
pkg/github/pullrequests_test.go | 84 +++++++++++++++++++++++++++------
1 file changed, 70 insertions(+), 14 deletions(-)
diff --git a/pkg/github/pullrequests_test.go b/pkg/github/pullrequests_test.go
index 30efe4f69..761de5010 100644
--- a/pkg/github/pullrequests_test.go
+++ b/pkg/github/pullrequests_test.go
@@ -171,9 +171,17 @@ func Test_ListPullRequests(t *testing.T) {
{
name: "successful PRs listing",
mockedClient: mock.NewMockedHTTPClient(
- mock.WithRequestMatch(
+ mock.WithRequestMatchHandler(
mock.GetReposPullsByOwnerByRepo,
- mockPRs,
+ expectQueryParams(t, map[string]string{
+ "state": "all",
+ "sort": "created",
+ "direction": "desc",
+ "per_page": "30",
+ "page": "1",
+ }).andThen(
+ mockResponse(t, http.StatusOK, mockPRs),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -281,9 +289,15 @@ func Test_MergePullRequest(t *testing.T) {
{
name: "successful merge",
mockedClient: mock.NewMockedHTTPClient(
- mock.WithRequestMatch(
+ mock.WithRequestMatchHandler(
mock.PutReposPullsMergeByOwnerByRepoByPullNumber,
- mockMergeResult,
+ expectRequestBody(t, map[string]interface{}{
+ "commit_title": "Merge PR #42",
+ "commit_message": "Merging awesome feature",
+ "merge_method": "squash",
+ }).andThen(
+ mockResponse(t, http.StatusOK, mockMergeResult),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -662,7 +676,11 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PutReposPullsUpdateBranchByOwnerByRepoByPullNumber,
- mockResponse(t, http.StatusAccepted, mockUpdateResult),
+ expectRequestBody(t, map[string]interface{}{
+ "expected_head_sha": "abcd1234",
+ }).andThen(
+ mockResponse(t, http.StatusAccepted, mockUpdateResult),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -679,7 +697,9 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PutReposPullsUpdateBranchByOwnerByRepoByPullNumber,
- mockResponse(t, http.StatusAccepted, mockUpdateResult),
+ expectRequestBody(t, map[string]interface{}{}).andThen(
+ mockResponse(t, http.StatusAccepted, mockUpdateResult),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -1030,9 +1050,14 @@ func Test_CreatePullRequestReview(t *testing.T) {
{
name: "successful review creation with body only",
mockedClient: mock.NewMockedHTTPClient(
- mock.WithRequestMatch(
+ mock.WithRequestMatchHandler(
mock.PostReposPullsReviewsByOwnerByRepoByPullNumber,
- mockReview,
+ expectRequestBody(t, map[string]interface{}{
+ "body": "Looks good!",
+ "event": "APPROVE",
+ }).andThen(
+ mockResponse(t, http.StatusOK, mockReview),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -1048,9 +1073,15 @@ func Test_CreatePullRequestReview(t *testing.T) {
{
name: "successful review creation with commit_id",
mockedClient: mock.NewMockedHTTPClient(
- mock.WithRequestMatch(
+ mock.WithRequestMatchHandler(
mock.PostReposPullsReviewsByOwnerByRepoByPullNumber,
- mockReview,
+ expectRequestBody(t, map[string]interface{}{
+ "body": "Looks good!",
+ "event": "APPROVE",
+ "commit_id": "abcdef123456",
+ }).andThen(
+ mockResponse(t, http.StatusOK, mockReview),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -1067,9 +1098,26 @@ func Test_CreatePullRequestReview(t *testing.T) {
{
name: "successful review creation with comments",
mockedClient: mock.NewMockedHTTPClient(
- mock.WithRequestMatch(
+ mock.WithRequestMatchHandler(
mock.PostReposPullsReviewsByOwnerByRepoByPullNumber,
- mockReview,
+ expectRequestBody(t, map[string]interface{}{
+ "body": "Some issues to fix",
+ "event": "REQUEST_CHANGES",
+ "comments": []interface{}{
+ map[string]interface{}{
+ "path": "file1.go",
+ "position": float64(10),
+ "body": "This needs to be fixed",
+ },
+ map[string]interface{}{
+ "path": "file2.go",
+ "position": float64(20),
+ "body": "Consider a different approach here",
+ },
+ },
+ }).andThen(
+ mockResponse(t, http.StatusOK, mockReview),
+ ),
),
),
requestArgs: map[string]interface{}{
@@ -1240,10 +1288,18 @@ func Test_CreatePullRequest(t *testing.T) {
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PostReposPullsByOwnerByRepo,
- mockResponse(t, http.StatusCreated, mockPR),
+ expectRequestBody(t, map[string]interface{}{
+ "title": "Test PR",
+ "body": "This is a test PR",
+ "head": "feature-branch",
+ "base": "main",
+ "draft": false,
+ "maintainer_can_modify": true,
+ }).andThen(
+ mockResponse(t, http.StatusCreated, mockPR),
+ ),
),
),
-
requestArgs: map[string]interface{}{
"owner": "owner",
"repo": "repo",
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/github/github-mcp-server/pull/95.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy