MCPcopy Index your code
hub / github.com/github/github-mcp-server / Test_UpdatePullRequestBranch

Function Test_UpdatePullRequestBranch

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

Source from the content-addressed store, hash-verified

1757}
1758
1759func Test_UpdatePullRequestBranch(t *testing.T) {
1760 // Verify tool definition once
1761 serverTool := UpdatePullRequestBranch(translations.NullTranslationHelper)
1762 tool := serverTool.Tool
1763 require.NoError(t, toolsnaps.Test(tool.Name, tool))
1764
1765 assert.Equal(t, "update_pull_request_branch", tool.Name)
1766 assert.NotEmpty(t, tool.Description)
1767 schema := tool.InputSchema.(*jsonschema.Schema)
1768 assert.Contains(t, schema.Properties, "owner")
1769 assert.Contains(t, schema.Properties, "repo")
1770 assert.Contains(t, schema.Properties, "pullNumber")
1771 assert.Contains(t, schema.Properties, "expectedHeadSha")
1772 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "pullNumber"})
1773
1774 // Setup mock update result for success case
1775 mockUpdateResult := &github.PullRequestBranchUpdateResponse{
1776 Message: github.Ptr("Branch was updated successfully"),
1777 URL: github.Ptr("https://api.github.com/repos/owner/repo/pulls/42"),
1778 }
1779
1780 tests := []struct {
1781 name string
1782 mockedClient *http.Client
1783 requestArgs map[string]any
1784 expectError bool
1785 expectedUpdateResult *github.PullRequestBranchUpdateResponse
1786 expectedErrMsg string
1787 }{
1788 {
1789 name: "successful branch update",
1790 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
1791 PutReposPullsUpdateBranchByOwnerByRepoByPullNumber: expectRequestBody(t, map[string]any{
1792 "expected_head_sha": "abcd1234",
1793 }).andThen(
1794 mockResponse(t, http.StatusAccepted, mockUpdateResult),
1795 ),
1796 }),
1797 requestArgs: map[string]any{
1798 "owner": "owner",
1799 "repo": "repo",
1800 "pullNumber": float64(42),
1801 "expectedHeadSha": "abcd1234",
1802 },
1803 expectError: false,
1804 expectedUpdateResult: mockUpdateResult,
1805 },
1806 {
1807 name: "branch update without expected SHA",
1808 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
1809 PutReposPullsUpdateBranchByOwnerByRepoByPullNumber: expectRequestBody(t, map[string]any{}).andThen(
1810 mockResponse(t, http.StatusAccepted, mockUpdateResult),
1811 ),
1812 }),
1813 requestArgs: map[string]any{
1814 "owner": "owner",
1815 "repo": "repo",
1816 "pullNumber": float64(42),

Callers

nothing calls this directly

Calls 14

TestFunction · 0.92
UpdatePullRequestBranchFunction · 0.85
expectRequestBodyFunction · 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