add tests for humanize
This commit is contained in:
parent
13fc592d0a
commit
ee2ac63ff8
1 changed files with 24 additions and 0 deletions
24
humanize/time_test.go
Normal file
24
humanize/time_test.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package humanize
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var timeSinceTests = []struct {
|
||||
in time.Time
|
||||
out string
|
||||
}{
|
||||
{time.Now().AddDate(0, 0, -1), "1 day"},
|
||||
{time.Now().AddDate(0, -1, -1), "1 month 1 day"},
|
||||
{time.Now().Add(time.Minute * -10), "10 mins"},
|
||||
{time.Now().Add(time.Minute * -10 + time.Second * -30), "10 mins 30 secs"},
|
||||
}
|
||||
|
||||
func TestTimeSince(t *testing.T) {
|
||||
for _, testCase := range timeSinceTests {
|
||||
if since := TimeSince(testCase.in); since != testCase.out {
|
||||
t.Errorf("Incorrect time since string. Expected %s, Actual: %s", testCase.out, since)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue