This commit is contained in:
41
cmd/cli/flag_test.go
Normal file
41
cmd/cli/flag_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPeriodSetT(t *testing.T) {
|
||||
now := time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
cases := map[string]time.Time{
|
||||
"2001-02-03": time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC),
|
||||
"2001-02": time.Date(2001, 2, 1, 0, 0, 0, 0, time.UTC),
|
||||
"2001": time.Date(2001, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
"": time.Unix(0, 0),
|
||||
"1m": now.Add(1 * time.Minute),
|
||||
"+1m": now.Add(1 * time.Minute),
|
||||
"-1m": now.Add(-1 * time.Minute),
|
||||
"1h1m": now.Add(1*time.Hour + 1*time.Minute),
|
||||
"1d": now.Add(24 * time.Hour),
|
||||
"+1d": now.Add(24 * time.Hour),
|
||||
"-1d": now.Add(-24 * time.Hour),
|
||||
"1d1m": now.Add(24*time.Hour + 1*time.Minute),
|
||||
"+1d1m": now.Add(24*time.Hour + 1*time.Minute),
|
||||
"-1d1m": now.Add(-1*24*time.Hour + -1*1*time.Minute),
|
||||
"1y1mo1w1d1h": now.AddDate(1, 1, 7+1).Add(1 * time.Hour),
|
||||
}
|
||||
|
||||
for input, expect := range cases {
|
||||
input, expect := input, expect
|
||||
t.Run(input, func(t *testing.T) {
|
||||
p := &Period{}
|
||||
var got time.Time
|
||||
if _, err := p.setT(now, input, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Unix() != expect.Unix() {
|
||||
t.Errorf("expected %s but got %s", expect.String(), got.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user