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

Function Test_GetPullRequest

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

Source from the content-addressed store, hash-verified

19)
20
21func Test_GetPullRequest(t *testing.T) {
22 // Verify tool definition once
23 serverTool := PullRequestRead(translations.NullTranslationHelper)
24 tool := serverTool.Tool
25 require.NoError(t, toolsnaps.Test(tool.Name, tool))
26
27 assert.Equal(t, "pull_request_read", tool.Name)
28 assert.NotEmpty(t, tool.Description)
29 schema := tool.InputSchema.(*jsonschema.Schema)
30 assert.Contains(t, schema.Properties, "method")
31 assert.Contains(t, schema.Properties, "owner")
32 assert.Contains(t, schema.Properties, "repo")
33 assert.Contains(t, schema.Properties, "pullNumber")
34 assert.ElementsMatch(t, schema.Required, []string{"method", "owner", "repo", "pullNumber"})
35
36 // Setup mock PR for success case
37 mockPR := &github.PullRequest{
38 Number: github.Ptr(42),
39 Title: github.Ptr("Test PR"),
40 State: github.Ptr("open"),
41 HTMLURL: github.Ptr("https://github.com/owner/repo/pull/42"),
42 Head: &github.PullRequestBranch{
43 SHA: github.Ptr("abcd1234"),
44 Ref: github.Ptr("feature-branch"),
45 },
46 Base: &github.PullRequestBranch{
47 Ref: github.Ptr("main"),
48 },
49 Body: github.Ptr("This is a test PR"),
50 User: &github.User{
51 Login: github.Ptr("testuser"),
52 },
53 }
54
55 tests := []struct {
56 name string
57 mockedClient *http.Client
58 requestArgs map[string]any
59 expectError bool
60 expectedPR *github.PullRequest
61 expectedErrMsg string
62 }{
63 {
64 name: "successful PR fetch",
65 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
66 GetReposPullsByOwnerByRepoByPullNumber: mockResponse(t, http.StatusOK, mockPR),
67 }),
68 requestArgs: map[string]any{
69 "method": "get",
70 "owner": "owner",
71 "repo": "repo",
72 "pullNumber": float64(42),
73 },
74 expectError: false,
75 expectedPR: mockPR,
76 },
77 {
78 name: "PR fetch fails",

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
NewMockedHTTPClientFunction · 0.92
PullRequestReadFunction · 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