TestValidateExpressions tests expression safety and runtime-import validation.
(t *testing.T)
| 18 | |
| 19 | // TestValidateExpressions tests expression safety and runtime-import validation. |
| 20 | func TestValidateExpressions(t *testing.T) { |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | markdown string |
| 24 | shouldError bool |
| 25 | errorContains string |
| 26 | }{ |
| 27 | { |
| 28 | name: "no expressions", |
| 29 | markdown: "# Hello\n\nNo expressions here.", |
| 30 | shouldError: false, |
| 31 | }, |
| 32 | { |
| 33 | name: "safe expression", |
| 34 | markdown: "# Hello\n\n${{ github.event.issue.number }}", |
| 35 | shouldError: false, |
| 36 | }, |
| 37 | { |
| 38 | name: "unsafe expression in markdown", |
| 39 | markdown: "# Hello\n\n${{ github.event.issue.body }}", |
| 40 | shouldError: true, |
| 41 | errorContains: "unauthorized expressions found", |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | for _, tt := range tests { |
| 46 | t.Run(tt.name, func(t *testing.T) { |
| 47 | tmpDir := testutil.TempDir(t, "expr-test") |
| 48 | markdownPath := filepath.Join(tmpDir, "test.md") |
| 49 | |
| 50 | compiler := NewCompiler() |
| 51 | workflowData := &WorkflowData{ |
| 52 | Name: "Test", |
| 53 | MarkdownContent: tt.markdown, |
| 54 | AI: "copilot", |
| 55 | } |
| 56 | |
| 57 | err := compiler.validateExpressions(workflowData, markdownPath) |
| 58 | if tt.shouldError { |
| 59 | require.Error(t, err, "Expected validateExpressions to return an error") |
| 60 | if tt.errorContains != "" { |
| 61 | assert.Contains(t, err.Error(), tt.errorContains, "Error should contain expected message") |
| 62 | } |
| 63 | } else { |
| 64 | assert.NoError(t, err, "validateExpressions should not return an error") |
| 65 | } |
| 66 | }) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // TestValidateFeatureConfig tests feature flag and action-mode validation. |
| 71 | func TestValidateFeatureConfig(t *testing.T) { |
nothing calls this directly
no test coverage detected