(t *testing.T)
| 1757 | } |
| 1758 | |
| 1759 | func 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), |
nothing calls this directly
no test coverage detected