MCPcopy Create free account
hub / github.com/gavv/httpexpect / WithMatcher

Method WithMatcher

request.go:351–378  ·  view source on GitHub ↗

WithMatcher attaches a matcher to the request. All attached matchers are invoked in the Expect method for a newly created Response. Example: req := NewRequestC(config, "GET", "/path") req.WithMatcher(func (resp *httpexpect.Response) { resp.Header("API-Version").NotEmpty() })

(matcher func(*Response))

Source from the content-addressed store, hash-verified

349// resp.Header("API-Version").NotEmpty()
350// })
351func (r *Request) WithMatcher(matcher func(*Response)) *Request {
352 opChain := r.chain.enter("WithMatcher()")
353 defer opChain.leave()
354
355 r.mu.Lock()
356 defer r.mu.Unlock()
357
358 if opChain.failed() {
359 return r
360 }
361
362 if !r.checkOrder(opChain, "WithMatcher()") {
363 return r
364 }
365
366 if matcher == nil {
367 opChain.fail(AssertionFailure{
368 Type: AssertUsage,
369 Errors: []error{
370 errors.New("unexpected nil argument"),
371 },
372 })
373 return r
374 }
375
376 r.matchers = append(r.matchers, matcher)
377 return r
378}
379
380// WithTransformer attaches a transform to the Request.
381// All attachhed transforms are invoked in the Expect methods for

Callers 6

RequestMethod · 0.80
TestRequest_FailedChainFunction · 0.80
TestRequest_ReentrancyFunction · 0.80
TestRequest_MatchersFunction · 0.80
TestRequest_UsageFunction · 0.80
TestRequest_OrderFunction · 0.80

Calls 7

checkOrderMethod · 0.95
enterMethod · 0.80
leaveMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 5

TestRequest_FailedChainFunction · 0.64
TestRequest_ReentrancyFunction · 0.64
TestRequest_MatchersFunction · 0.64
TestRequest_UsageFunction · 0.64
TestRequest_OrderFunction · 0.64