(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func Test_SearchRepositories(t *testing.T) { |
| 19 | // Verify tool definition once |
| 20 | serverTool := SearchRepositories(translations.NullTranslationHelper) |
| 21 | tool := serverTool.Tool |
| 22 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 23 | |
| 24 | assert.Equal(t, "search_repositories", tool.Name) |
| 25 | assert.NotEmpty(t, tool.Description) |
| 26 | |
| 27 | schema, ok := tool.InputSchema.(*jsonschema.Schema) |
| 28 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 29 | assert.Contains(t, schema.Properties, "query") |
| 30 | assert.Contains(t, schema.Properties, "sort") |
| 31 | assert.Contains(t, schema.Properties, "order") |
| 32 | assert.Contains(t, schema.Properties, "page") |
| 33 | assert.Contains(t, schema.Properties, "perPage") |
| 34 | assert.ElementsMatch(t, schema.Required, []string{"query"}) |
| 35 | |
| 36 | // Setup mock search results |
| 37 | mockSearchResult := &github.RepositoriesSearchResult{ |
| 38 | Total: github.Ptr(2), |
| 39 | IncompleteResults: github.Ptr(false), |
| 40 | Repositories: []*github.Repository{ |
| 41 | { |
| 42 | ID: github.Ptr(int64(12345)), |
| 43 | Name: github.Ptr("repo-1"), |
| 44 | FullName: github.Ptr("owner/repo-1"), |
| 45 | HTMLURL: github.Ptr("https://github.com/owner/repo-1"), |
| 46 | Description: github.Ptr("Test repository 1"), |
| 47 | StargazersCount: github.Ptr(100), |
| 48 | }, |
| 49 | { |
| 50 | ID: github.Ptr(int64(67890)), |
| 51 | Name: github.Ptr("repo-2"), |
| 52 | FullName: github.Ptr("owner/repo-2"), |
| 53 | HTMLURL: github.Ptr("https://github.com/owner/repo-2"), |
| 54 | Description: github.Ptr("Test repository 2"), |
| 55 | StargazersCount: github.Ptr(50), |
| 56 | }, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | tests := []struct { |
| 61 | name string |
| 62 | mockedClient *http.Client |
| 63 | requestArgs map[string]any |
| 64 | expectError bool |
| 65 | expectedResult *github.RepositoriesSearchResult |
| 66 | expectedErrMsg string |
| 67 | }{ |
| 68 | { |
| 69 | name: "successful repository search", |
| 70 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 71 | GetSearchRepositories: expectQueryParams(t, map[string]string{ |
| 72 | "q": "golang test", |
| 73 | "sort": "stars", |
| 74 | "order": "desc", |
| 75 | "page": "2", |
nothing calls this directly
no test coverage detected