MCPcopy
hub / github.com/caddyserver/caddy / BenchmarkMatchExpressionMatch

Function BenchmarkMatchExpressionMatch

modules/caddyhttp/celmatcher_test.go:503–543  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

501}
502
503func BenchmarkMatchExpressionMatch(b *testing.B) {
504 for _, tst := range matcherTests {
505 tc := tst
506 if tc.wantErr {
507 continue
508 }
509 b.Run(tst.name, func(b *testing.B) {
510 tc.expression.Provision(caddy.Context{})
511 req := httptest.NewRequest(tc.httpMethod, tc.urlTarget, nil)
512 if tc.httpHeader != nil {
513 req.Header = *tc.httpHeader
514 }
515 repl := caddy.NewReplacer()
516 ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
517 ctx = context.WithValue(ctx, VarsCtxKey, map[string]any{
518 "foo": "bar",
519 })
520 req = req.WithContext(ctx)
521 addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
522 if tc.clientCertificate != nil {
523 block, _ := pem.Decode(clientCert)
524 if block == nil {
525 b.Fatalf("failed to decode PEM certificate")
526 }
527
528 cert, err := x509.ParseCertificate(block.Bytes)
529 if err != nil {
530 b.Fatalf("failed to decode PEM certificate: %v", err)
531 }
532
533 req.TLS = &tls.ConnectionState{
534 PeerCertificates: []*x509.Certificate{cert},
535 }
536 }
537 b.ResetTimer()
538 for b.Loop() {
539 tc.expression.MatchWithError(req)
540 }
541 })
542 }
543}
544
545func TestMatchExpressionProvision(t *testing.T) {
546 tests := []struct {

Callers

nothing calls this directly

Calls 4

addHTTPVarsToReplacerFunction · 0.85
WithValueMethod · 0.80
ProvisionMethod · 0.65
MatchWithErrorMethod · 0.65

Tested by

no test coverage detected