(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func Test_GetGist(t *testing.T) { |
| 187 | // Verify tool definition |
| 188 | serverTool := GetGist(translations.NullTranslationHelper) |
| 189 | tool := serverTool.Tool |
| 190 | |
| 191 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 192 | |
| 193 | assert.Equal(t, "get_gist", tool.Name) |
| 194 | assert.NotEmpty(t, tool.Description) |
| 195 | assert.True(t, tool.Annotations.ReadOnlyHint, "get_gist tool should be read-only") |
| 196 | |
| 197 | schema, ok := tool.InputSchema.(*jsonschema.Schema) |
| 198 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 199 | assert.Contains(t, schema.Properties, "gist_id") |
| 200 | |
| 201 | assert.Contains(t, schema.Required, "gist_id") |
| 202 | |
| 203 | // Setup mock gist for success case |
| 204 | mockGist := github.Gist{ |
| 205 | ID: github.Ptr("gist1"), |
| 206 | Description: github.Ptr("First Gist"), |
| 207 | HTMLURL: github.Ptr("https://gist.github.com/user/gist1"), |
| 208 | Public: github.Ptr(true), |
| 209 | CreatedAt: &github.Timestamp{Time: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)}, |
| 210 | Owner: &github.User{Login: github.Ptr("user")}, |
| 211 | Files: map[github.GistFilename]github.GistFile{ |
| 212 | github.GistFilename("file1.txt"): { |
| 213 | Filename: github.Ptr("file1.txt"), |
| 214 | Content: github.Ptr("content of file 1"), |
| 215 | }, |
| 216 | }, |
| 217 | } |
| 218 | |
| 219 | tests := []struct { |
| 220 | name string |
| 221 | mockedClient *http.Client |
| 222 | requestArgs map[string]any |
| 223 | expectError bool |
| 224 | expectedGists github.Gist |
| 225 | expectedErrMsg string |
| 226 | }{ |
| 227 | { |
| 228 | name: "Successful fetching different gist", |
| 229 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 230 | GetGistsByGistID: mockResponse(t, http.StatusOK, mockGist), |
| 231 | }), |
| 232 | requestArgs: map[string]any{ |
| 233 | "gist_id": "gist1", |
| 234 | }, |
| 235 | expectError: false, |
| 236 | expectedGists: mockGist, |
| 237 | }, |
| 238 | { |
| 239 | name: "gist_id parameter missing", |
| 240 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 241 | GetGistsByGistID: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 242 | w.WriteHeader(http.StatusUnprocessableEntity) |
| 243 | _, _ = w.Write([]byte(`{"message": "Invalid Request"}`)) |
nothing calls this directly
no test coverage detected