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

Method WithQueryString

request.go:1417–1454  ·  view source on GitHub ↗

WithQueryString parses given query string and adds it to request URL. Example: req := NewRequestC(config, "PUT", "http://example.com/path") req.WithQuery("a", 11) req.WithQueryString("b=22&c=33") // URL is now http://example.com/path?a=11&bb=22&c=33

(query string)

Source from the content-addressed store, hash-verified

1415// req.WithQueryString("b=22&c=33")
1416// // URL is now http://example.com/path?a=11&bb=22&c=33
1417func (r *Request) WithQueryString(query string) *Request {
1418 opChain := r.chain.enter("WithQueryString()")
1419 defer opChain.leave()
1420
1421 r.mu.Lock()
1422 defer r.mu.Unlock()
1423
1424 if opChain.failed() {
1425 return r
1426 }
1427
1428 if !r.checkOrder(opChain, "WithQueryString()") {
1429 return r
1430 }
1431
1432 v, err := url.ParseQuery(query)
1433
1434 if err != nil {
1435 opChain.fail(AssertionFailure{
1436 Type: AssertValid,
1437 Actual: &AssertionValue{query},
1438 Errors: []error{
1439 errors.New("invalid query string"),
1440 err,
1441 },
1442 })
1443 return r
1444 }
1445
1446 if r.query == nil {
1447 r.query = make(url.Values)
1448 }
1449 for k, v := range v {
1450 r.query[k] = append(r.query[k], v...)
1451 }
1452
1453 return r
1454}
1455
1456// WithURL sets request URL.
1457//

Callers 3

TestRequest_FailedChainFunction · 0.80
TestRequest_URLQueryFunction · 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 3

TestRequest_FailedChainFunction · 0.64
TestRequest_URLQueryFunction · 0.64
TestRequest_OrderFunction · 0.64