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

Function Test_ListPullRequests

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

Source from the content-addressed store, hash-verified

571}
572
573func Test_ListPullRequests(t *testing.T) {
574 // Verify tool definition once
575 serverTool := ListPullRequests(translations.NullTranslationHelper)
576 tool := serverTool.Tool
577 require.NoError(t, toolsnaps.Test(tool.Name, tool))
578
579 assert.Equal(t, "list_pull_requests", tool.Name)
580 assert.NotEmpty(t, tool.Description)
581 schema := tool.InputSchema.(*jsonschema.Schema)
582 assert.Contains(t, schema.Properties, "owner")
583 assert.Contains(t, schema.Properties, "repo")
584 assert.Contains(t, schema.Properties, "state")
585 assert.Contains(t, schema.Properties, "head")
586 assert.Contains(t, schema.Properties, "base")
587 assert.Contains(t, schema.Properties, "sort")
588 assert.Contains(t, schema.Properties, "direction")
589 assert.Contains(t, schema.Properties, "perPage")
590 assert.Contains(t, schema.Properties, "page")
591 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo"})
592
593 // Setup mock PRs for success case
594 mockPRs := []*github.PullRequest{
595 {
596 Number: github.Ptr(42),
597 Title: github.Ptr("First PR"),
598 State: github.Ptr("open"),
599 HTMLURL: github.Ptr("https://github.com/owner/repo/pull/42"),
600 },
601 {
602 Number: github.Ptr(43),
603 Title: github.Ptr("Second PR"),
604 State: github.Ptr("closed"),
605 HTMLURL: github.Ptr("https://github.com/owner/repo/pull/43"),
606 },
607 }
608
609 tests := []struct {
610 name string
611 mockedClient *http.Client
612 requestArgs map[string]any
613 expectError bool
614 expectedPRs []*github.PullRequest
615 expectedErrMsg string
616 }{
617 {
618 name: "successful PRs listing",
619 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
620 GetReposPullsByOwnerByRepo: expectQueryParams(t, map[string]string{
621 "state": "all",
622 "sort": "created",
623 "direction": "desc",
624 "per_page": "30",
625 "page": "1",
626 }).andThen(
627 mockResponse(t, http.StatusOK, mockPRs),
628 ),
629 }),
630 requestArgs: map[string]any{

Callers

nothing calls this directly

Calls 14

TestFunction · 0.92
ListPullRequestsFunction · 0.85
expectQueryParamsFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
andThenMethod · 0.80
WriteHeaderMethod · 0.80

Tested by

no test coverage detected