(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestWorkflowDispatchInjection(t *testing.T) { |
| 76 | compiler := NewCompiler() |
| 77 | |
| 78 | testCases := []struct { |
| 79 | name string |
| 80 | onSection string |
| 81 | expected string |
| 82 | }{ |
| 83 | { |
| 84 | name: "Simple issues trigger", |
| 85 | onSection: `on: |
| 86 | issues: |
| 87 | types: [opened, edited]`, |
| 88 | expected: "workflow_dispatch:", |
| 89 | }, |
| 90 | { |
| 91 | name: "Complex triggers with issues", |
| 92 | onSection: `on: |
| 93 | push: |
| 94 | branches: [main] |
| 95 | issues: |
| 96 | types: [opened] |
| 97 | pull_request:`, |
| 98 | expected: "workflow_dispatch:", |
| 99 | }, |
| 100 | } |
| 101 | |
| 102 | for _, tc := range testCases { |
| 103 | t.Run(tc.name, func(t *testing.T) { |
| 104 | result := compiler.injectWorkflowDispatchForIssue(tc.onSection) |
| 105 | if !strings.Contains(result, tc.expected) { |
| 106 | t.Errorf("injectWorkflowDispatchForIssue() result does not contain %s\nGot: %s", tc.expected, result) |
| 107 | } |
| 108 | // Check that issue_number input is added |
| 109 | if !strings.Contains(result, "issue_number") { |
| 110 | t.Errorf("injectWorkflowDispatchForIssue() result does not contain issue_number input") |
| 111 | } |
| 112 | }) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | func TestIssueNumberReplacement(t *testing.T) { |
| 117 | compiler := NewCompiler() |
nothing calls this directly
no test coverage detected