TestRealWorldExpressionPatterns tests common expression patterns used in GitHub Actions
(t *testing.T)
| 532 | |
| 533 | // TestRealWorldExpressionPatterns tests common expression patterns used in GitHub Actions |
| 534 | func 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 |
| 571 | func TestExpressionNodeWithDescription(t *testing.T) { |
nothing calls this directly
no test coverage detected