(t *testing.T)
| 440 | } |
| 441 | |
| 442 | func TestFileDeletion(t *testing.T) { |
| 443 | t.Parallel() |
| 444 | |
| 445 | mcpClient := setupMCPClient(t) |
| 446 | |
| 447 | ctx := context.Background() |
| 448 | |
| 449 | // First, who am I |
| 450 | |
| 451 | t.Log("Getting current user...") |
| 452 | resp, err := mcpClient.CallTool(ctx, &mcp.CallToolParams{Name: "get_me"}) |
| 453 | require.NoError(t, err, "expected to call 'get_me' tool successfully") |
| 454 | require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) |
| 455 | |
| 456 | require.False(t, resp.IsError, "expected result not to be an error") |
| 457 | require.Len(t, resp.Content, 1, "expected content to have one item") |
| 458 | |
| 459 | textContent, ok := resp.Content[0].(*mcp.TextContent) |
| 460 | require.True(t, ok, "expected content to be of type TextContent") |
| 461 | |
| 462 | var trimmedGetMeText struct { |
| 463 | Login string `json:"login"` |
| 464 | } |
| 465 | err = json.Unmarshal([]byte(textContent.Text), &trimmedGetMeText) |
| 466 | require.NoError(t, err, "expected to unmarshal text content successfully") |
| 467 | |
| 468 | currentOwner := trimmedGetMeText.Login |
| 469 | |
| 470 | // Then create a repository with a README (via autoInit) |
| 471 | repoName := fmt.Sprintf("github-mcp-server-e2e-%s-%d", t.Name(), time.Now().UnixMilli()) |
| 472 | t.Logf("Creating repository %s/%s...", currentOwner, repoName) |
| 473 | _, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ |
| 474 | Name: "create_repository", |
| 475 | Arguments: map[string]any{ |
| 476 | "name": repoName, |
| 477 | "private": true, |
| 478 | "autoInit": true, |
| 479 | }, |
| 480 | }) |
| 481 | require.NoError(t, err, "expected to call 'get_me' tool successfully") |
| 482 | require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) |
| 483 | |
| 484 | // Cleanup the repository after the test |
| 485 | t.Cleanup(func() { |
| 486 | // MCP Server doesn't support deletions, but we can use the GitHub Client |
| 487 | ghClient := getRESTClient(t) |
| 488 | t.Logf("Deleting repository %s/%s...", currentOwner, repoName) |
| 489 | _, err := ghClient.Repositories.Delete(context.Background(), currentOwner, repoName) |
| 490 | require.NoError(t, err, "expected to delete repository successfully") |
| 491 | }) |
| 492 | |
| 493 | // Create a branch on which to create a new commit |
| 494 | |
| 495 | t.Logf("Creating branch in %s/%s...", currentOwner, repoName) |
| 496 | resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ |
| 497 | Name: "create_branch", |
| 498 | Arguments: map[string]any{ |
| 499 | "owner": currentOwner, |
nothing calls this directly
no test coverage detected