(t *testing.T)
| 627 | } |
| 628 | |
| 629 | func TestDirectoryDeletion(t *testing.T) { |
| 630 | t.Parallel() |
| 631 | |
| 632 | mcpClient := setupMCPClient(t) |
| 633 | |
| 634 | ctx := context.Background() |
| 635 | |
| 636 | // First, who am I |
| 637 | |
| 638 | t.Log("Getting current user...") |
| 639 | resp, err := mcpClient.CallTool(ctx, &mcp.CallToolParams{Name: "get_me"}) |
| 640 | require.NoError(t, err, "expected to call 'get_me' tool successfully") |
| 641 | require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) |
| 642 | |
| 643 | require.False(t, resp.IsError, "expected result not to be an error") |
| 644 | require.Len(t, resp.Content, 1, "expected content to have one item") |
| 645 | |
| 646 | textContent, ok := resp.Content[0].(*mcp.TextContent) |
| 647 | require.True(t, ok, "expected content to be of type TextContent") |
| 648 | |
| 649 | var trimmedGetMeText struct { |
| 650 | Login string `json:"login"` |
| 651 | } |
| 652 | err = json.Unmarshal([]byte(textContent.Text), &trimmedGetMeText) |
| 653 | require.NoError(t, err, "expected to unmarshal text content successfully") |
| 654 | |
| 655 | currentOwner := trimmedGetMeText.Login |
| 656 | |
| 657 | // Then create a repository with a README (via autoInit) |
| 658 | repoName := fmt.Sprintf("github-mcp-server-e2e-%s-%d", t.Name(), time.Now().UnixMilli()) |
| 659 | t.Logf("Creating repository %s/%s...", currentOwner, repoName) |
| 660 | _, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ |
| 661 | Name: "create_repository", |
| 662 | Arguments: map[string]any{ |
| 663 | "name": repoName, |
| 664 | "private": true, |
| 665 | "autoInit": true, |
| 666 | }, |
| 667 | }) |
| 668 | require.NoError(t, err, "expected to call 'get_me' tool successfully") |
| 669 | require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) |
| 670 | |
| 671 | // Cleanup the repository after the test |
| 672 | t.Cleanup(func() { |
| 673 | // MCP Server doesn't support deletions, but we can use the GitHub Client |
| 674 | ghClient := getRESTClient(t) |
| 675 | t.Logf("Deleting repository %s/%s...", currentOwner, repoName) |
| 676 | _, err := ghClient.Repositories.Delete(context.Background(), currentOwner, repoName) |
| 677 | require.NoError(t, err, "expected to delete repository successfully") |
| 678 | }) |
| 679 | |
| 680 | // Create a branch on which to create a new commit |
| 681 | |
| 682 | t.Logf("Creating branch in %s/%s...", currentOwner, repoName) |
| 683 | resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ |
| 684 | Name: "create_branch", |
| 685 | Arguments: map[string]any{ |
| 686 | "owner": currentOwner, |
nothing calls this directly
no test coverage detected