--- Issue granular tool handler tests ---
(t *testing.T)
| 145 | // --- Issue granular tool handler tests --- |
| 146 | |
| 147 | func TestGranularCreateIssue(t *testing.T) { |
| 148 | mockIssue := &gogithub.Issue{ |
| 149 | Number: gogithub.Ptr(1), |
| 150 | Title: gogithub.Ptr("Test Issue"), |
| 151 | Body: gogithub.Ptr("Test body"), |
| 152 | } |
| 153 | |
| 154 | tests := []struct { |
| 155 | name string |
| 156 | mockedClient *http.Client |
| 157 | requestArgs map[string]any |
| 158 | expectedErrMsg string |
| 159 | }{ |
| 160 | { |
| 161 | name: "successful creation", |
| 162 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 163 | PostReposIssuesByOwnerByRepo: expectRequestBody(t, map[string]any{ |
| 164 | "title": "Test Issue", |
| 165 | "body": "Test body", |
| 166 | }).andThen(mockResponse(t, http.StatusCreated, mockIssue)), |
| 167 | }), |
| 168 | requestArgs: map[string]any{ |
| 169 | "owner": "owner", |
| 170 | "repo": "repo", |
| 171 | "title": "Test Issue", |
| 172 | "body": "Test body", |
| 173 | }, |
| 174 | }, |
| 175 | { |
| 176 | name: "missing required parameter", |
| 177 | mockedClient: MockHTTPClientWithHandlers(nil), |
| 178 | requestArgs: map[string]any{ |
| 179 | "owner": "owner", |
| 180 | "repo": "repo", |
| 181 | }, |
| 182 | expectedErrMsg: "missing required parameter: title", |
| 183 | }, |
| 184 | } |
| 185 | |
| 186 | for _, tc := range tests { |
| 187 | t.Run(tc.name, func(t *testing.T) { |
| 188 | client := mustNewGHClient(t, tc.mockedClient) |
| 189 | deps := BaseDeps{Client: client} |
| 190 | serverTool := GranularCreateIssue(translations.NullTranslationHelper) |
| 191 | handler := serverTool.Handler(deps) |
| 192 | |
| 193 | request := createMCPRequest(tc.requestArgs) |
| 194 | result, err := handler(ContextWithDeps(context.Background(), deps), &request) |
| 195 | require.NoError(t, err) |
| 196 | |
| 197 | if tc.expectedErrMsg != "" { |
| 198 | textContent := getTextResult(t, result) |
| 199 | assert.Contains(t, textContent.Text, tc.expectedErrMsg) |
| 200 | return |
| 201 | } |
| 202 | assert.False(t, result.IsError) |
| 203 | }) |
| 204 | } |
nothing calls this directly
no test coverage detected