(t *testing.T)
| 549 | } |
| 550 | |
| 551 | func TestApplyFrontmatterLineTransform(t *testing.T) { |
| 552 | tests := []struct { |
| 553 | name string |
| 554 | content string |
| 555 | transform func([]string) ([]string, bool) |
| 556 | wantApplied bool |
| 557 | wantContent string |
| 558 | wantErr bool |
| 559 | }{ |
| 560 | { |
| 561 | name: "transform applied", |
| 562 | content: `--- |
| 563 | on: workflow_dispatch |
| 564 | timeout_minutes: 30 |
| 565 | --- |
| 566 | |
| 567 | # Test`, |
| 568 | transform: func(lines []string) ([]string, bool) { |
| 569 | result := make([]string, len(lines)) |
| 570 | modified := false |
| 571 | for i, line := range lines { |
| 572 | if strings.Contains(line, "timeout_minutes") { |
| 573 | result[i] = strings.ReplaceAll(line, "timeout_minutes", "timeout-minutes") |
| 574 | modified = true |
| 575 | } else { |
| 576 | result[i] = line |
| 577 | } |
| 578 | } |
| 579 | return result, modified |
| 580 | }, |
| 581 | wantApplied: true, |
| 582 | wantContent: "timeout-minutes: 30", |
| 583 | }, |
| 584 | { |
| 585 | name: "no change returns original content", |
| 586 | content: `--- |
| 587 | on: workflow_dispatch |
| 588 | --- |
| 589 | |
| 590 | # Test`, |
| 591 | transform: func(lines []string) ([]string, bool) { |
| 592 | return lines, false |
| 593 | }, |
| 594 | wantApplied: false, |
| 595 | }, |
| 596 | { |
| 597 | name: "content with no frontmatter is handled gracefully", |
| 598 | content: "not valid frontmatter at all", |
| 599 | transform: func(lines []string) ([]string, bool) { |
| 600 | // transform returns false because there are no lines to modify |
| 601 | return lines, false |
| 602 | }, |
| 603 | wantApplied: false, |
| 604 | }, |
| 605 | { |
| 606 | name: "markdown body preserved", |
| 607 | content: `--- |
| 608 | on: workflow_dispatch |
nothing calls this directly
no test coverage detected