X Tutup
Skip to content

Commit a297153

Browse files
committed
test for utils.FuzzyAgo
1 parent bfdf89b commit a297153

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

utils/utils_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package utils
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
// TODO test FuzzyAgo
9+
10+
func TestFuzzyAgo(t *testing.T) {
11+
12+
cases := map[string]string{
13+
"1s": "less than a minute ago",
14+
"30s": "less than a minute ago",
15+
"1m08s": "about 1 minute ago",
16+
"15m0s": "about 15 minutes ago",
17+
"59m10s": "about 59 minutes ago",
18+
"1h10m02s": "about 1 hour ago",
19+
"15h0m01s": "about 15 hours ago",
20+
"30h10m": "about 1 day ago",
21+
"50h": "about 2 days ago",
22+
}
23+
24+
for duration, expected := range cases {
25+
d, e := time.ParseDuration(duration)
26+
if e != nil {
27+
t.Errorf("failed to create a duration: %s", e)
28+
}
29+
30+
fuzzy := FuzzyAgo(d)
31+
if fuzzy != expected {
32+
t.Errorf("unexpected fuzzy duration value: %s for %s", fuzzy, duration)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)
X Tutup