Atlas › Test

TestParseDuration

Exact test identity: go.temporal.io/server/common/nexus/nexusrpc/TestParseDuration

Package
go.temporal.io/server/common/nexus/nexusrpc
Suite / test hierarchy
TestParseDuration
Test
TestParseDuration
Introduced at
api.go ×2 Frontier kind: Joint frontier
Covered ranges
5
Covered lines
14
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/nexus/nexusrpc/api.go 14 covered LOC · 5 ranges

Open complete file

254 var durationRegexp = regexp.MustCompile(`^(\d+(?:\.\d+)?)(ms|s|m)$`)
255
256 > func ParseDuration(value string) (time.Duration, error) { api.go
257 > m := durationRegexp.FindStringSubmatch(value)
258 > if len(m) == 0 {
259 > return 0, fmt.Errorf("invalid duration: %q", value) api.go
260 > }
261 > v, err := strconv.ParseFloat(m[1], 64) api.go
262 > if err != nil {
263 return 0, err
264 }
265
266 > switch m[2] { api.go
267 > case "ms":
268 > return time.Millisecond * time.Duration(v), nil
269 > case "s": api.go
270 > return time.Millisecond * time.Duration(v*1e3), nil
271 > case "m":
272 > return time.Millisecond * time.Duration(v*1e3*60), nil
273 }
274 // nolint:forbidigo // code is unreachable due to regex validation