(t *testing.T)
| 552 | } |
| 553 | |
| 554 | func TestFixCommand_CommandToSlashCommandMigration(t *testing.T) { |
| 555 | // Create a temporary directory for test files |
| 556 | tmpDir := t.TempDir() |
| 557 | workflowFile := filepath.Join(tmpDir, "test-workflow.md") |
| 558 | |
| 559 | // Create a workflow with deprecated on.command field |
| 560 | content := `--- |
| 561 | on: |
| 562 | command: my-bot |
| 563 | |
| 564 | permissions: |
| 565 | contents: read |
| 566 | --- |
| 567 | |
| 568 | # Test Workflow |
| 569 | |
| 570 | This is a test workflow with slash command. |
| 571 | ` |
| 572 | |
| 573 | if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil { |
| 574 | t.Fatalf("Failed to create test file: %v", err) |
| 575 | } |
| 576 | |
| 577 | // Get the command migration codemod |
| 578 | commandCodemod := getCodemodByID("command-to-slash-command-migration") |
| 579 | if commandCodemod == nil { |
| 580 | t.Fatal("command-to-slash-command-migration codemod not found") |
| 581 | } |
| 582 | |
| 583 | // Process the file |
| 584 | fixed, _, err := processWorkflowFileWithInfo(workflowFile, []Codemod{*commandCodemod}, true, false) |
| 585 | if err != nil { |
| 586 | t.Fatalf("Failed to process workflow file: %v", err) |
| 587 | } |
| 588 | |
| 589 | if !fixed { |
| 590 | t.Error("Expected file to be fixed, but no changes were made") |
| 591 | } |
| 592 | |
| 593 | // Read the updated content |
| 594 | updatedContent, err := os.ReadFile(workflowFile) |
| 595 | if err != nil { |
| 596 | t.Fatalf("Failed to read updated file: %v", err) |
| 597 | } |
| 598 | |
| 599 | updatedStr := string(updatedContent) |
| 600 | |
| 601 | // Debug: print the content to see what we got |
| 602 | t.Logf("Updated content:\n%s", updatedStr) |
| 603 | |
| 604 | // Verify the change - check for the presence of slash_command |
| 605 | if !strings.Contains(updatedStr, "slash_command:") { |
| 606 | t.Errorf("Expected slash_command field, got:\n%s", updatedStr) |
| 607 | } |
| 608 | |
| 609 | // Check that standalone "command" field was replaced (not part of slash_command) |
| 610 | lines := strings.SplitSeq(updatedStr, "\n") |
| 611 | for line := range lines { |
nothing calls this directly
no test coverage detected