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

Function TestIfExpressionCleanHandling

pkg/workflow/if_expression_clean_test.go:13–89  ·  view source on GitHub ↗

TestIfExpressionCleanHandling tests that if expressions are handled cleanly without the "if: " prefix being added too early, and that multiline expressions use YAML folded style properly

(t *testing.T)

Source from the content-addressed store, hash-verified

11// without the "if: " prefix being added too early, and that multiline expressions
12// use YAML folded style properly
13func TestIfExpressionCleanHandling(t *testing.T) {
14 tests := []struct {
15 name string
16 expression string
17 isMultiline bool
18 expectedYAML string
19 expectsPrefix bool
20 }{
21 {
22 name: "simple single line expression",
23 expression: "github.event_name == 'push'",
24 isMultiline: false,
25 expectedYAML: " if: github.event_name == 'push'",
26 expectsPrefix: true,
27 },
28 {
29 name: "multiline expression with YAML folded style",
30 expression: `github.event_name == 'issues' ||
31github.event_name == 'pull_request' ||
32github.event_name == 'issue_comment'`,
33 isMultiline: true,
34 expectedYAML: ` if: >
35 github.event_name == 'issues' ||
36 github.event_name == 'pull_request' ||
37 github.event_name == 'issue_comment'`,
38 expectsPrefix: true,
39 },
40 {
41 name: "empty expression",
42 expression: "",
43 isMultiline: false,
44 expectedYAML: "",
45 expectsPrefix: false,
46 },
47 }
48
49 for _, tt := range tests {
50 t.Run(tt.name, func(t *testing.T) {
51 // Create a job with the expression
52 job := &Job{
53 Name: "test-job",
54 If: tt.expression, // Should store just the expression, not prefixed
55 RunsOn: "runs-on: ubuntu-latest",
56 Steps: []string{" - name: Test Step\n run: echo test\n"},
57 }
58
59 // Create job manager and render
60 jm := NewJobManager()
61 err := jm.AddJob(job)
62 if err != nil {
63 t.Fatalf("Failed to add job: %v", err)
64 }
65
66 var yamlBuf strings.Builder
67 jm.renderJobTo(&yamlBuf, job)
68 yaml := yamlBuf.String()
69
70 if tt.expression == "" {

Callers

nothing calls this directly

Calls 6

AddJobMethod · 0.95
renderJobToMethod · 0.95
NewJobManagerFunction · 0.85
RunMethod · 0.45
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected