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

Method WithQuery

request.go:1172–1203  ·  view source on GitHub ↗

WithQuery adds query parameter to request URL. value is converted to string using fmt.Sprint() and urlencoded. Example: req := NewRequestC(config, "PUT", "http://example.com/path") req.WithQuery("a", 123) req.WithQuery("b", "foo") // URL is now http://example.com/path?a=123&b=foo

(key string, value interface{})

Source from the content-addressed store, hash-verified

1170// req.WithQuery("b", "foo")
1171// // URL is now http://example.com/path?a=123&b=foo
1172func (r *Request) WithQuery(key string, value interface{}) *Request {
1173 opChain := r.chain.enter("WithQuery()")
1174 defer opChain.leave()
1175
1176 r.mu.Lock()
1177 defer r.mu.Unlock()
1178
1179 if opChain.failed() {
1180 return r
1181 }
1182
1183 if !r.checkOrder(opChain, "WithQuery()") {
1184 return r
1185 }
1186
1187 if value == nil {
1188 opChain.fail(AssertionFailure{
1189 Type: AssertUsage,
1190 Errors: []error{
1191 errors.New("unexpected nil argument"),
1192 },
1193 })
1194 return r
1195 }
1196
1197 if r.query == nil {
1198 r.query = make(url.Values)
1199 }
1200 r.query.Add(key, fmt.Sprint(value))
1201
1202 return r
1203}
1204
1205// WithQueryObject adds multiple query parameters to request URL.
1206//

Callers 6

TestRequest_FailedChainFunction · 0.80
TestRequest_URLQueryFunction · 0.80
TestRequest_UsageFunction · 0.80
TestRequest_OrderFunction · 0.80
TestIrisParamsFunction · 0.80
testBasicHandlerFunction · 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 6

TestRequest_FailedChainFunction · 0.64
TestRequest_URLQueryFunction · 0.64
TestRequest_UsageFunction · 0.64
TestRequest_OrderFunction · 0.64
TestIrisParamsFunction · 0.64
testBasicHandlerFunction · 0.64