(t *testing.T)
| 1567 | } |
| 1568 | |
| 1569 | func Test_CreateOrUpdateFile(t *testing.T) { |
| 1570 | // Verify tool definition once |
| 1571 | serverTool := CreateOrUpdateFile(translations.NullTranslationHelper) |
| 1572 | tool := serverTool.Tool |
| 1573 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 1574 | |
| 1575 | schema, ok := tool.InputSchema.(*jsonschema.Schema) |
| 1576 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 1577 | |
| 1578 | assert.Equal(t, "create_or_update_file", tool.Name) |
| 1579 | assert.NotEmpty(t, tool.Description) |
| 1580 | assert.Contains(t, schema.Properties, "owner") |
| 1581 | assert.Contains(t, schema.Properties, "repo") |
| 1582 | assert.Contains(t, schema.Properties, "path") |
| 1583 | assert.Contains(t, schema.Properties, "content") |
| 1584 | assert.Contains(t, schema.Properties, "message") |
| 1585 | assert.Contains(t, schema.Properties, "branch") |
| 1586 | assert.Contains(t, schema.Properties, "sha") |
| 1587 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "path", "content", "message", "branch"}) |
| 1588 | |
| 1589 | // Setup mock file content response |
| 1590 | mockFileResponse := &github.RepositoryContentResponse{ |
| 1591 | Content: &github.RepositoryContent{ |
| 1592 | Name: github.Ptr("example.md"), |
| 1593 | Path: github.Ptr("docs/example.md"), |
| 1594 | SHA: github.Ptr("abc123def456"), |
| 1595 | Size: github.Ptr(42), |
| 1596 | HTMLURL: github.Ptr("https://github.com/owner/repo/blob/main/docs/example.md"), |
| 1597 | DownloadURL: github.Ptr("https://raw.githubusercontent.com/owner/repo/main/docs/example.md"), |
| 1598 | }, |
| 1599 | Commit: github.Commit{ |
| 1600 | SHA: github.Ptr("def456abc789"), |
| 1601 | Message: github.Ptr("Add example file"), |
| 1602 | Author: &github.CommitAuthor{ |
| 1603 | Name: github.Ptr("Test User"), |
| 1604 | Email: github.Ptr("test@example.com"), |
| 1605 | Date: &github.Timestamp{Time: time.Now()}, |
| 1606 | }, |
| 1607 | HTMLURL: github.Ptr("https://github.com/owner/repo/commit/def456abc789"), |
| 1608 | }, |
| 1609 | } |
| 1610 | |
| 1611 | tests := []struct { |
| 1612 | name string |
| 1613 | mockedClient *http.Client |
| 1614 | requestArgs map[string]any |
| 1615 | expectError bool |
| 1616 | expectedContent *github.RepositoryContentResponse |
| 1617 | expectedErrMsg string |
| 1618 | }{ |
| 1619 | { |
| 1620 | name: "successful file creation", |
| 1621 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 1622 | PutReposContentsByOwnerByRepoByPath: expectRequestBody(t, map[string]any{ |
| 1623 | "message": "Add example file", |
| 1624 | "content": "IyBFeGFtcGxlCgpUaGlzIGlzIGFuIGV4YW1wbGUgZmlsZS4=", // Base64 encoded content |
| 1625 | "branch": "main", |
| 1626 | }).andThen( |
nothing calls this directly
no test coverage detected