mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8403#discussion_r1976110052 Signed-off-by: hagen1778 <[email protected]>
30 lines
602 B
Go
30 lines
602 B
Go
package timeutil
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestParseDuration(t *testing.T) {
|
|
f := func(s string, resultExpected time.Duration) {
|
|
t.Helper()
|
|
result, err := ParseDuration(s)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %s", err)
|
|
}
|
|
if result != resultExpected {
|
|
t.Fatalf("unexpected result; got %v; want %v", result, resultExpected)
|
|
}
|
|
}
|
|
|
|
f("0", 0)
|
|
f("1s", time.Second)
|
|
f("1m", time.Minute)
|
|
f("1h", time.Hour)
|
|
f("1d", time.Hour*24)
|
|
f("1w", time.Hour*24*7)
|
|
f("1m30s", time.Minute+time.Second*30)
|
|
f("-1m30s", -(time.Minute + time.Second*30))
|
|
f("1d-4h", time.Hour*20)
|
|
}
|