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

Function TestAddIssueComment

pkg/github/issues_test.go:4104–4358  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4102}
4103
4104func TestAddIssueComment(t *testing.T) {
4105 t.Parallel()
4106
4107 serverTool := AddIssueComment(translations.NullTranslationHelper)
4108 tool := serverTool.Tool
4109 require.NoError(t, toolsnaps.Test(tool.Name, tool))
4110
4111 assert.Equal(t, "add_issue_comment", tool.Name)
4112 assert.NotEmpty(t, tool.Description)
4113 schema := tool.InputSchema.(*jsonschema.Schema)
4114 assert.Contains(t, schema.Properties, "owner")
4115 assert.Contains(t, schema.Properties, "repo")
4116 assert.Contains(t, schema.Properties, "issue_number")
4117 assert.Contains(t, schema.Properties, "comment_id")
4118 assert.Contains(t, schema.Properties, "body")
4119 assert.Contains(t, schema.Properties, "reaction")
4120 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "issue_number"})
4121
4122 mockComment := &github.IssueComment{
4123 ID: github.Ptr(int64(456)),
4124 Body: github.Ptr("This is a comment"),
4125 HTMLURL: github.Ptr("https://github.com/owner/repo/issues/42#issuecomment-456"),
4126 }
4127 mockReaction := &github.Reaction{
4128 ID: github.Ptr(int64(789)),
4129 Content: github.Ptr("heart"),
4130 }
4131 mockIssueComment := &github.IssueComment{
4132 ID: github.Ptr(int64(999)),
4133 IssueURL: github.Ptr("https://api.github.com/repos/owner/repo/issues/42"),
4134 }
4135 commentCreatedAfterReactionFailure := &atomic.Bool{}
4136
4137 tests := []struct {
4138 name string
4139 mockedClient *http.Client
4140 requestArgs map[string]any
4141 expectToolError bool
4142 expectedToolErrMsg string
4143 unexpectedCall *atomic.Bool
4144 }{
4145 {
4146 name: "successful comment on issue",
4147 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
4148 PostReposIssuesCommentsByOwnerByRepoByIssueNumber: mockResponse(t, http.StatusCreated, mockComment),
4149 }),
4150 requestArgs: map[string]any{
4151 "owner": "owner",
4152 "repo": "repo",
4153 "issue_number": float64(42),
4154 "body": "This is a comment",
4155 },
4156 },
4157 {
4158 name: "successful reaction to issue",
4159 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
4160 PostReposIssuesReactionsByOwnerByRepoByIssueNumber: mockResponse(t, http.StatusCreated, mockReaction),
4161 }),

Callers

nothing calls this directly

Calls 12

TestFunction · 0.92
AddIssueCommentFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
WriteHeaderMethod · 0.80
WriteMethod · 0.45
HandlerMethod · 0.45

Tested by

no test coverage detected