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

Function TestRealWorldExpressionPatterns

pkg/workflow/expressions_test.go:534–568  ·  view source on GitHub ↗

TestRealWorldExpressionPatterns tests common expression patterns used in GitHub Actions

(t *testing.T)

Source from the content-addressed store, hash-verified

532
533// TestRealWorldExpressionPatterns tests common expression patterns used in GitHub Actions
534func TestRealWorldExpressionPatterns(t *testing.T) {
535 tests := []struct {
536 name string
537 expression ConditionNode
538 expected string
539 }{
540 {
541 name: "run on main branch only",
542 expression: BuildEquals(
543 BuildPropertyAccess("github.ref"),
544 BuildStringLiteral("refs/heads/main"),
545 ),
546 expected: "github.ref == 'refs/heads/main'",
547 },
548 {
549 name: "skip draft PRs",
550 expression: &AndNode{
551 Left: BuildEventTypeEquals("pull_request"),
552 Right: &NotNode{
553 Child: BuildPropertyAccess("github.event.pull_request.draft"),
554 },
555 },
556 // ComparisonNode is not wrapped in AND; NotNode is wrapped (YAML ! safety)
557 expected: "github.event_name == 'pull_request' && (!(github.event.pull_request.draft))",
558 },
559 }
560
561 for _, tt := range tests {
562 t.Run(tt.name, func(t *testing.T) {
563 if result := tt.expression.Render(); result != tt.expected {
564 t.Errorf("Expected '%s', got '%s'", tt.expected, result)
565 }
566 })
567 }
568}
569
570// TestExpressionNodeWithDescription tests ExpressionNode with description field
571func TestExpressionNodeWithDescription(t *testing.T) {

Callers

nothing calls this directly

Calls 7

BuildEqualsFunction · 0.85
BuildPropertyAccessFunction · 0.85
BuildStringLiteralFunction · 0.85
BuildEventTypeEqualsFunction · 0.85
RenderMethod · 0.65
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected