mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
lib/timeutil: add test for ParseDuration
See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8403#discussion_r1976110052 Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
29
lib/timeutil/duration_test.go
Normal file
29
lib/timeutil/duration_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user