1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-06-24 22:26:56 +02:00

Add timeutil test

This commit is contained in:
ebosas
2021-11-19 09:20:18 +02:00
parent a9bec5e2ab
commit a82b12a314
2 changed files with 31 additions and 0 deletions

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
test:
go test ./internal/timeutil

View File

@ -0,0 +1,29 @@
package timeutil
import (
"testing"
"time"
)
func TestFormatDuration(t *testing.T) {
now := time.Now().Unix() * 1000
var tests = []struct {
input int64
want string
}{
{now, "less than a minute"},
{now - 1.4*60*1000, "1 minute"},
{now - 1.5*60*1000, "2 minutes"},
{now - 44*60*1000, "44 minutes"},
{now - 2*60*60*1000, "about 2 hours"},
{now - 1439*60*1000, "about 24 hours"},
{now - 1440*60*1000, "1 day"},
{now - 3*43200*60*1000, "3 months"},
{now - 24*43200*60*1000, "about 2 years"},
}
for _, test := range tests {
if got := FormatDuration(test.input); got != test.want {
t.Errorf("FormatDuration(%d) = %q, want %q", test.input, got, test.want)
}
}
}