diff --git a/pkg/lib/util/path_util.go b/pkg/lib/util/path_util.go index f9f0069..46e726a 100644 --- a/pkg/lib/util/path_util.go +++ b/pkg/lib/util/path_util.go @@ -1,14 +1,10 @@ package util import ( - "regexp" "strconv" + "strings" ) -// pathSpecRegex validates and (via its capture groups) breaks up a -// path spec string in a single step (see ParsePathSpec). -var pathSpecRegex *regexp.Regexp = regexp.MustCompile(`^([0-9]*)@(.+)$`) - // PathSpec is a path specifier for including tests within manifests. type PathSpec struct { // ParallelRuns matches the number of parallel runs specified @@ -21,30 +17,19 @@ type PathSpec struct { // ParsePathSpec tries to parse the given string into a PathSpec. // -// It returns a boolean result that indicates if parsing was successful -// (i.e. if s is a valid path specifier). -func ParsePathSpec(s string) (PathSpec, bool) { - matches := pathSpecRegex.FindStringSubmatch(s) - if matches == nil { - return PathSpec{}, false - } - - spec := PathSpec{ - ParallelRuns: 1, - Path: matches[2], // can't be empty, or else it wouldn't match the regex +// It returns a boolean result that indicates if parsing was successful (i.e. if +// s is a valid path specifier). The string takes the format "[n]@file.json". +func ParsePathSpec(s string) (spec PathSpec, ok bool) { + var parallelRuns string + parallelRuns, spec.Path, ok = strings.Cut(s, "@") + if parallelRuns != "" { + spec.ParallelRuns, _ = strconv.Atoi(parallelRuns) + } else { + spec.ParallelRuns = 1 } - - // Determine number of parallel runs, if supplied - if matches[1] != "" { - prs, err := strconv.Atoi(matches[1]) - if err != nil { - // matches[1] is all digits, so there must be something seriously wrong - panic("error Atoi-ing all-decimal regex match") - } - - spec.ParallelRuns = prs + if !ok || spec.Path == "" || spec.ParallelRuns <= 0 { + return PathSpec{}, false } - return spec, true } diff --git a/test/parallel/check_collected_responses.json b/test/parallel/check_collected_responses.json index 564d76a..1eceb32 100644 --- a/test/parallel/check_collected_responses.json +++ b/test/parallel/check_collected_responses.json @@ -1,8 +1,8 @@ [ { - "name": "bounce-json: bounce collected responses from N={{datastore "n_parallel"}} parallel runs: {{ datastore "responses" }}", + "name": "bounce-json: bounce collected responses from N={{datastore `n_parallel` }} parallel runs: {{ datastore `responses` }}", "request": { - "server_url": "http://localhost{{ datastore "local_port" }}", + "server_url": "http://localhost{{ datastore `local_port` }}", "endpoint": "bounce-json", "method": "POST", "body": { diff --git a/test/parallel/parallel.json b/test/parallel/parallel.json index 75b9d71..d07a68f 100644 --- a/test/parallel/parallel.json +++ b/test/parallel/parallel.json @@ -2,7 +2,7 @@ { "name": "bounce-json: bounce n=1", "request": { - "server_url": "http://localhost{{ datastore "local_port" }}", + "server_url": "http://localhost{{ datastore `local_port` }}", "endpoint": "bounce-json", "method": "POST", "body": {