(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func Test_GetRepositoryTree(t *testing.T) { |
| 19 | // Verify tool definition once |
| 20 | toolDef := GetRepositoryTree(translations.NullTranslationHelper) |
| 21 | require.NoError(t, toolsnaps.Test(toolDef.Tool.Name, toolDef.Tool)) |
| 22 | |
| 23 | assert.Equal(t, "get_repository_tree", toolDef.Tool.Name) |
| 24 | assert.NotEmpty(t, toolDef.Tool.Description) |
| 25 | |
| 26 | // Type assert the InputSchema to access its properties |
| 27 | inputSchema, ok := toolDef.Tool.InputSchema.(*jsonschema.Schema) |
| 28 | require.True(t, ok, "expected InputSchema to be *jsonschema.Schema") |
| 29 | assert.Contains(t, inputSchema.Properties, "owner") |
| 30 | assert.Contains(t, inputSchema.Properties, "repo") |
| 31 | assert.Contains(t, inputSchema.Properties, "tree_sha") |
| 32 | assert.Contains(t, inputSchema.Properties, "recursive") |
| 33 | assert.Contains(t, inputSchema.Properties, "path_filter") |
| 34 | assert.ElementsMatch(t, inputSchema.Required, []string{"owner", "repo"}) |
| 35 | |
| 36 | // Setup mock data |
| 37 | mockRepo := &github.Repository{ |
| 38 | DefaultBranch: github.Ptr("main"), |
| 39 | } |
| 40 | mockTree := &github.Tree{ |
| 41 | SHA: github.Ptr("abc123"), |
| 42 | Truncated: github.Ptr(false), |
| 43 | Entries: []*github.TreeEntry{ |
| 44 | { |
| 45 | Path: github.Ptr("README.md"), |
| 46 | Mode: github.Ptr("100644"), |
| 47 | Type: github.Ptr("blob"), |
| 48 | SHA: github.Ptr("file1sha"), |
| 49 | Size: github.Ptr(123), |
| 50 | URL: github.Ptr("https://api.github.com/repos/owner/repo/git/blobs/file1sha"), |
| 51 | }, |
| 52 | { |
| 53 | Path: github.Ptr("src/main.go"), |
| 54 | Mode: github.Ptr("100644"), |
| 55 | Type: github.Ptr("blob"), |
| 56 | SHA: github.Ptr("file2sha"), |
| 57 | Size: github.Ptr(456), |
| 58 | URL: github.Ptr("https://api.github.com/repos/owner/repo/git/blobs/file2sha"), |
| 59 | }, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | tests := []struct { |
| 64 | name string |
| 65 | mockedClient *http.Client |
| 66 | requestArgs map[string]any |
| 67 | expectError bool |
| 68 | expectedErrMsg string |
| 69 | }{ |
| 70 | { |
| 71 | name: "successfully get repository tree", |
| 72 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 73 | GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo), |
| 74 | GetReposGitTreesByOwnerByRepoByTree: mockResponse(t, http.StatusOK, mockTree), |
| 75 | }), |
nothing calls this directly
no test coverage detected