support 1w, 1d for loop
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
@@ -142,3 +143,28 @@ func testReq() *http.Request {
|
||||
"d": "e, f,g"
|
||||
}`))
|
||||
}
|
||||
|
||||
func TestToDuration(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
input string
|
||||
want time.Duration
|
||||
}{
|
||||
"invalid": {},
|
||||
"simple": {input: "1s", want: time.Second},
|
||||
"compound": {input: "1m1s", want: time.Minute + time.Second},
|
||||
"compound:unsorted": {input: "1s1m", want: time.Minute + time.Second},
|
||||
"extension:day": {input: "1d", want: 24 * time.Hour},
|
||||
"extension:week": {input: "1w", want: 24 * 7 * time.Hour},
|
||||
"extension:week,day": {input: "1w1d", want: 24 * 8 * time.Hour},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got := ToDuration(c.input)
|
||||
if got != c.want {
|
||||
t.Fatal(c.input, c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user