MCPcopy
hub / github.com/github/github-mcp-server / Test_GetPullRequestFiles

Function Test_GetPullRequestFiles

pkg/github/pullrequests_test.go:1107–1262  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1105}
1106
1107func Test_GetPullRequestFiles(t *testing.T) {
1108 // Verify tool definition once
1109 serverTool := PullRequestRead(translations.NullTranslationHelper)
1110 tool := serverTool.Tool
1111 require.NoError(t, toolsnaps.Test(tool.Name, tool))
1112
1113 assert.Equal(t, "pull_request_read", tool.Name)
1114 assert.NotEmpty(t, tool.Description)
1115 schema := tool.InputSchema.(*jsonschema.Schema)
1116 assert.Contains(t, schema.Properties, "method")
1117 assert.Contains(t, schema.Properties, "owner")
1118 assert.Contains(t, schema.Properties, "repo")
1119 assert.Contains(t, schema.Properties, "pullNumber")
1120 assert.Contains(t, schema.Properties, "page")
1121 assert.Contains(t, schema.Properties, "perPage")
1122 assert.ElementsMatch(t, schema.Required, []string{"method", "owner", "repo", "pullNumber"})
1123
1124 // Setup mock PR files for success case
1125 mockFiles := []*github.CommitFile{
1126 {
1127 Filename: github.Ptr("file1.go"),
1128 Status: github.Ptr("modified"),
1129 Additions: github.Ptr(10),
1130 Deletions: github.Ptr(5),
1131 Changes: github.Ptr(15),
1132 Patch: github.Ptr("@@ -1,5 +1,10 @@"),
1133 },
1134 {
1135 Filename: github.Ptr("file2.go"),
1136 Status: github.Ptr("added"),
1137 Additions: github.Ptr(20),
1138 Deletions: github.Ptr(0),
1139 Changes: github.Ptr(20),
1140 Patch: github.Ptr("@@ -0,0 +1,20 @@"),
1141 },
1142 }
1143
1144 tests := []struct {
1145 name string
1146 mockedClient *http.Client
1147 requestArgs map[string]any
1148 expectError bool
1149 expectedFiles []*github.CommitFile
1150 expectedErrMsg string
1151 }{
1152 {
1153 name: "successful files fetch",
1154 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
1155 GetReposPullsFilesByOwnerByRepoByPullNumber: expectQueryParams(t, map[string]string{
1156 "page": "1",
1157 "per_page": "30",
1158 }).andThen(
1159 mockResponse(t, http.StatusOK, mockFiles),
1160 ),
1161 }),
1162 requestArgs: map[string]any{
1163 "method": "get_files",
1164 "owner": "owner",

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
PullRequestReadFunction · 0.85
expectQueryParamsFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
stubRepoAccessCacheFunction · 0.85
stubFeatureFlagsFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85

Tested by

no test coverage detected