(b *testing.B)
| 981 | } |
| 982 | |
| 983 | func BenchmarkHeaderREMatcher(b *testing.B) { |
| 984 | i := 0 |
| 985 | match := MatchHeaderRE{"Field": &MatchRegexp{Pattern: "^foo(.*)$", Name: "name"}} |
| 986 | input := http.Header{"Field": []string{"foobar"}} |
| 987 | var host string |
| 988 | err := match.Provision(caddy.Context{}) |
| 989 | if err != nil { |
| 990 | b.Errorf("Test %d %v: Provisioning: %v", i, match, err) |
| 991 | } |
| 992 | err = match.Validate() |
| 993 | if err != nil { |
| 994 | b.Errorf("Test %d %v: Validating: %v", i, match, err) |
| 995 | } |
| 996 | |
| 997 | // set up the fake request and its Replacer |
| 998 | req := &http.Request{Header: input, URL: new(url.URL), Host: host} |
| 999 | repl := caddy.NewReplacer() |
| 1000 | ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl) |
| 1001 | req = req.WithContext(ctx) |
| 1002 | addHTTPVarsToReplacer(repl, req, httptest.NewRecorder()) |
| 1003 | for b.Loop() { |
| 1004 | match.MatchWithError(req) |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | func TestVarREMatcher(t *testing.T) { |
| 1009 | for i, tc := range []struct { |
nothing calls this directly
no test coverage detected