(t *testing.T)
| 411 | } |
| 412 | |
| 413 | func TestFixCommand_PreservesFormatting(t *testing.T) { |
| 414 | // Create a temporary directory for test files |
| 415 | tmpDir := t.TempDir() |
| 416 | workflowFile := filepath.Join(tmpDir, "test-workflow.md") |
| 417 | |
| 418 | // Create a workflow with comments and specific formatting |
| 419 | content := `--- |
| 420 | on: |
| 421 | workflow_dispatch: |
| 422 | |
| 423 | # Timeout configuration |
| 424 | timeout_minutes: 30 # 30 minutes should be enough |
| 425 | |
| 426 | permissions: |
| 427 | contents: read |
| 428 | --- |
| 429 | |
| 430 | # Test Workflow |
| 431 | |
| 432 | This is a test workflow. |
| 433 | ` |
| 434 | |
| 435 | if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil { |
| 436 | t.Fatalf("Failed to create test file: %v", err) |
| 437 | } |
| 438 | |
| 439 | // Get the timeout migration codemod |
| 440 | timeoutCodemod := getCodemodByID("timeout-minutes-migration") |
| 441 | if timeoutCodemod == nil { |
| 442 | t.Fatal("timeout-minutes-migration codemod not found") |
| 443 | } |
| 444 | |
| 445 | // Process the file |
| 446 | fixed, _, err := processWorkflowFileWithInfo(workflowFile, []Codemod{*timeoutCodemod}, true, false) |
| 447 | if err != nil { |
| 448 | t.Fatalf("Failed to process workflow file: %v", err) |
| 449 | } |
| 450 | |
| 451 | if !fixed { |
| 452 | t.Error("Expected file to be fixed, but no changes were made") |
| 453 | } |
| 454 | |
| 455 | // Read the updated content |
| 456 | updatedContent, err := os.ReadFile(workflowFile) |
| 457 | if err != nil { |
| 458 | t.Fatalf("Failed to read updated file: %v", err) |
| 459 | } |
| 460 | |
| 461 | updatedStr := string(updatedContent) |
| 462 | |
| 463 | // Verify the comment is preserved |
| 464 | if !strings.Contains(updatedStr, "# 30 minutes should be enough") { |
| 465 | t.Error("Expected inline comment to be preserved") |
| 466 | } |
| 467 | |
| 468 | // Verify the block comment is preserved |
| 469 | if !strings.Contains(updatedStr, "# Timeout configuration") { |
| 470 | t.Error("Expected block comment to be preserved") |
nothing calls this directly
no test coverage detected