(t *testing.T)
| 504 | } |
| 505 | |
| 506 | func TestMatchExpressionMatch(t *testing.T) { |
| 507 | for _, tst := range expressionTests { |
| 508 | tc := tst |
| 509 | t.Run(tc.name, func(t *testing.T) { |
| 510 | caddyCtx, cancel := caddy.NewContext(caddy.Context{Context: context.Background()}) |
| 511 | defer cancel() |
| 512 | err := tc.expression.Provision(caddyCtx) |
| 513 | if err != nil { |
| 514 | if !tc.wantErr { |
| 515 | t.Errorf("MatchExpression.Provision() error = %v, wantErr %v", err, tc.wantErr) |
| 516 | } |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | req := httptest.NewRequest(tc.httpMethod, tc.urlTarget, nil) |
| 521 | if tc.httpHeader != nil { |
| 522 | req.Header = *tc.httpHeader |
| 523 | } |
| 524 | repl := caddyhttp.NewTestReplacer(req) |
| 525 | repl.Set("http.vars.root", "./testdata") |
| 526 | ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl) |
| 527 | req = req.WithContext(ctx) |
| 528 | |
| 529 | matches, err := tc.expression.MatchWithError(req) |
| 530 | if err != nil { |
| 531 | t.Errorf("MatchExpression.Match() error = %v", err) |
| 532 | return |
| 533 | } |
| 534 | if matches != tc.wantResult { |
| 535 | t.Errorf("MatchExpression.Match() expected to return '%t', for expression : '%s'", tc.wantResult, tc.expression.Expr) |
| 536 | } |
| 537 | |
| 538 | if tc.expectedPath != "" { |
| 539 | path, ok := repl.Get("http.matchers.file.relative") |
| 540 | if !ok { |
| 541 | t.Errorf("MatchExpression.Match() expected to return path '%s', but got none", tc.expectedPath) |
| 542 | } |
| 543 | if path != tc.expectedPath { |
| 544 | t.Errorf("MatchExpression.Match() expected to return path '%s', but got '%s'", tc.expectedPath, path) |
| 545 | } |
| 546 | } |
| 547 | }) |
| 548 | } |
| 549 | } |
nothing calls this directly
no test coverage detected