(t *testing.T)
| 744 | } |
| 745 | |
| 746 | func Test_ForkRepository(t *testing.T) { |
| 747 | // Verify tool definition once |
| 748 | serverTool := ForkRepository(translations.NullTranslationHelper) |
| 749 | tool := serverTool.Tool |
| 750 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 751 | |
| 752 | schema, ok := tool.InputSchema.(*jsonschema.Schema) |
| 753 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 754 | |
| 755 | assert.Equal(t, "fork_repository", tool.Name) |
| 756 | assert.NotEmpty(t, tool.Description) |
| 757 | assert.Contains(t, schema.Properties, "owner") |
| 758 | assert.Contains(t, schema.Properties, "repo") |
| 759 | assert.Contains(t, schema.Properties, "organization") |
| 760 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo"}) |
| 761 | |
| 762 | // Setup mock forked repo for success case |
| 763 | mockForkedRepo := &github.Repository{ |
| 764 | ID: github.Ptr(int64(123456)), |
| 765 | Name: github.Ptr("repo"), |
| 766 | FullName: github.Ptr("new-owner/repo"), |
| 767 | Owner: &github.User{ |
| 768 | Login: github.Ptr("new-owner"), |
| 769 | }, |
| 770 | HTMLURL: github.Ptr("https://github.com/new-owner/repo"), |
| 771 | DefaultBranch: github.Ptr("main"), |
| 772 | Fork: github.Ptr(true), |
| 773 | ForksCount: github.Ptr(0), |
| 774 | } |
| 775 | |
| 776 | tests := []struct { |
| 777 | name string |
| 778 | mockedClient *http.Client |
| 779 | requestArgs map[string]any |
| 780 | expectError bool |
| 781 | expectedRepo *github.Repository |
| 782 | expectedErrMsg string |
| 783 | }{ |
| 784 | { |
| 785 | name: "successful repository fork", |
| 786 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 787 | PostReposForksByOwnerByRepo: mockResponse(t, http.StatusAccepted, mockForkedRepo), |
| 788 | }), |
| 789 | requestArgs: map[string]any{ |
| 790 | "owner": "owner", |
| 791 | "repo": "repo", |
| 792 | }, |
| 793 | expectError: false, |
| 794 | expectedRepo: mockForkedRepo, |
| 795 | }, |
| 796 | { |
| 797 | name: "repository fork fails", |
| 798 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 799 | PostReposForksByOwnerByRepo: func(w http.ResponseWriter, _ *http.Request) { |
| 800 | w.WriteHeader(http.StatusForbidden) |
| 801 | _, _ = w.Write([]byte(`{"message": "Forbidden"}`)) |
| 802 | }, |
| 803 | }), |
nothing calls this directly
no test coverage detected