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

Function TestApplyFrontmatterLineTransform

pkg/cli/yaml_frontmatter_utils_test.go:551–644  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

549}
550
551func 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: `---
563on: workflow_dispatch
564timeout_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: `---
587on: 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: `---
608on: workflow_dispatch

Callers

nothing calls this directly

Calls 3

RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected