| 543 | } |
| 544 | |
| 545 | func TestMatchExpressionProvision(t *testing.T) { |
| 546 | tests := []struct { |
| 547 | name string |
| 548 | expression *MatchExpression |
| 549 | wantErr bool |
| 550 | }{ |
| 551 | { |
| 552 | name: "boolean matches succeed", |
| 553 | expression: &MatchExpression{ |
| 554 | Expr: "{http.request.uri.query} != ''", |
| 555 | }, |
| 556 | wantErr: false, |
| 557 | }, |
| 558 | { |
| 559 | name: "reject expressions with non-boolean results", |
| 560 | expression: &MatchExpression{ |
| 561 | Expr: "{http.request.uri.query}", |
| 562 | }, |
| 563 | wantErr: true, |
| 564 | }, |
| 565 | } |
| 566 | for _, tt := range tests { |
| 567 | t.Run(tt.name, func(t *testing.T) { |
| 568 | ctx, cancel := caddy.NewContext(caddy.Context{Context: context.Background()}) |
| 569 | defer cancel() |
| 570 | if err := tt.expression.Provision(ctx); (err != nil) != tt.wantErr { |
| 571 | t.Errorf("MatchExpression.Provision() error = %v, wantErr %v", err, tt.wantErr) |
| 572 | } |
| 573 | }) |
| 574 | } |
| 575 | } |