MCPcopy Index your code
hub / github.com/gavv/httpexpect / GetString

Method GetString

environment.go:317–342  ·  view source on GitHub ↗

GetString returns value stored in the environment, casted to string. If value does not exist, or is not string, reports failure and returns empty string. Example: value := env.GetString("key")

(key string)

Source from the content-addressed store, hash-verified

315//
316// value := env.GetString("key")
317func (e *Environment) GetString(key string) string {
318 opChain := e.chain.enter("GetString(%q)", key)
319 defer opChain.leave()
320
321 e.mu.RLock()
322 defer e.mu.RUnlock()
323
324 value, ok := envValue(opChain, e.data, key)
325 if !ok {
326 return ""
327 }
328
329 casted, ok := value.(string)
330 if !ok {
331 opChain.fail(AssertionFailure{
332 Type: AssertType,
333 Actual: &AssertionValue{value},
334 Errors: []error{
335 errors.New("expected: string value"),
336 },
337 })
338 return ""
339 }
340
341 return casted
342}
343
344// GetBytes returns value stored in the environment, casted to []byte.
345//

Callers 3

TestEnvironment_NotFoundFunction · 0.80
TestEnvironment_StringFunction · 0.80
IrisHandlerFunction · 0.80

Calls 4

envValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failMethod · 0.80

Tested by 2

TestEnvironment_NotFoundFunction · 0.64
TestEnvironment_StringFunction · 0.64