Atlas › Test

valid_timer_duration

Exact test identity: go.temporal.io/server/common/primitives/timestamp/TestValidateAndCapProtoDuration/valid_timer_duration

Package
go.temporal.io/server/common/primitives/timestamp
Suite / test hierarchy
TestValidateAndCapProtoDuration/valid_timer_duration
Test
valid_timer_duration
Introduced at
duration.go ×2 Frontier kind: Joint frontier
Covered ranges
5
Covered lines
6
Covered files
1

Co-introduced tests

1 other test enter at the same concept.

Covered source

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

go.temporal.io/server/common/primitives/timestamp/duration.go 6 covered LOC · 5 ranges

Open complete file

65 // durationpb.CheckValid cannot be used directly because it will return an error for
66 // very large durations, but we are okay with truncating these.
67 > func ValidateAndCapProtoDuration(d *durationpb.Duration) error { duration.go
68 > if d == nil {
69 // nil durations are converted to 0 value
70 return nil
71 }
72
73 > if (d.GetSeconds() > 0 && d.GetNanos() < 0) || (d.GetSeconds() < 0 && d.GetNanos() > 0) { duration.go
74 return errMismatchedSigns
75 }
76
77 // this is a best effort conversion and will return the closest value in the event of overflow.
78 > if d.AsDuration() < 0 { duration.go
79 return errNegativeDuration
80 }
81
82 > if d.AsDuration() > maxAllowedDuration { duration.go
83 d.Seconds = maxSeconds
84 d.Nanos = 0 // A year is always a round number of seconds.
85 }
86
87 > return nil duration.go
88 }