MCPcopy Create free account
hub / github.com/github/gh-aw / TestFixCommand_PreservesFormatting

Function TestFixCommand_PreservesFormatting

pkg/cli/fix_command_test.go:413–477  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

411}
412
413func 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 := `---
420on:
421 workflow_dispatch:
422
423# Timeout configuration
424timeout_minutes: 30 # 30 minutes should be enough
425
426permissions:
427 contents: read
428---
429
430# Test Workflow
431
432This 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")

Callers

nothing calls this directly

Calls 4

getCodemodByIDFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected