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

Method Glob

environment.go:489–518  ·  view source on GitHub ↗

Glob accepts a glob pattern and returns a sorted slice of keys that match the pattern. If the pattern is invalid, reports failure and returns an empty slice. Example: env := NewEnvironment(t) for _, key := range env.Glob("foo.*") { ... }

(pattern string)

Source from the content-addressed store, hash-verified

487// ...
488// }
489func (e *Environment) Glob(pattern string) []string {
490 opChain := e.chain.enter("Glob(%q)", pattern)
491 defer opChain.leave()
492
493 e.mu.RLock()
494 defer e.mu.RUnlock()
495
496 glb, err := glob.Compile(pattern)
497 if err != nil {
498 opChain.fail(AssertionFailure{
499 Type: AssertUsage,
500 Errors: []error{
501 errors.New("unexpected invalid glob pattern"),
502 },
503 })
504 return []string{}
505 }
506
507 keys := []string{}
508 for key := range e.data {
509 if glb.Match(key) {
510 keys = append(keys, key)
511 }
512 }
513
514 sort.Slice(keys, func(i, j int) bool {
515 return keys[i] < keys[j]
516 })
517 return keys
518}
519
520func envValue(chain *chain, env map[string]interface{}, key string) (interface{}, bool) {
521 v, ok := env[key]

Callers 1

TestEnvironment_GlobFunction · 0.80

Calls 4

enterMethod · 0.80
leaveMethod · 0.80
failMethod · 0.80
MatchMethod · 0.80

Tested by 1

TestEnvironment_GlobFunction · 0.64