(t *testing.T)
| 296 | } |
| 297 | |
| 298 | func TestValidateExpressionContent(t *testing.T) { |
| 299 | tests := []struct { |
| 300 | name string |
| 301 | expr string |
| 302 | fullGroup string |
| 303 | wantErr bool |
| 304 | errorInMsg string |
| 305 | }{ |
| 306 | { |
| 307 | name: "simple property access", |
| 308 | expr: "github.ref", |
| 309 | fullGroup: "test-${{ github.ref }}", |
| 310 | wantErr: false, |
| 311 | }, |
| 312 | { |
| 313 | name: "OR expression", |
| 314 | expr: "github.event.issue.number || github.ref", |
| 315 | fullGroup: "test-${{ github.event.issue.number || github.ref }}", |
| 316 | wantErr: false, |
| 317 | }, |
| 318 | { |
| 319 | name: "expression with parentheses", |
| 320 | expr: "(github.workflow || github.ref) && github.repository", |
| 321 | fullGroup: "test-${{ (github.workflow || github.ref) && github.repository }}", |
| 322 | wantErr: false, |
| 323 | }, |
| 324 | { |
| 325 | name: "unclosed parenthesis", |
| 326 | expr: "(github.workflow", |
| 327 | fullGroup: "test-${{ (github.workflow }}", |
| 328 | wantErr: true, |
| 329 | errorInMsg: "unclosed parentheses", |
| 330 | }, |
| 331 | { |
| 332 | name: "extra closing parenthesis", |
| 333 | expr: "github.workflow)", |
| 334 | fullGroup: "test-${{ github.workflow) }}", |
| 335 | wantErr: true, |
| 336 | errorInMsg: "unbalanced parentheses", |
| 337 | }, |
| 338 | { |
| 339 | name: "unclosed single quote", |
| 340 | expr: "github.workflow == 'test", |
| 341 | fullGroup: "test-${{ github.workflow == 'test }}", |
| 342 | wantErr: true, |
| 343 | errorInMsg: "unclosed single quote", |
| 344 | }, |
| 345 | { |
| 346 | name: "consecutive operators", |
| 347 | expr: "github.workflow && && github.ref", |
| 348 | fullGroup: "test-${{ github.workflow && && github.ref }}", |
| 349 | wantErr: true, |
| 350 | errorInMsg: "invalid expression syntax", |
| 351 | }, |
| 352 | } |
| 353 | |
| 354 | for _, tt := range tests { |
| 355 | t.Run(tt.name, func(t *testing.T) { |
nothing calls this directly
no test coverage detected