Added assert package and added test
parent
514c24a768
commit
36ade8290a
@ -0,0 +1,49 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.runcible.io/learning/ratchet/internal/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHumanDate(t *testing.T) {
|
||||||
|
|
||||||
|
// Table driven test
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
tm time.Time
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "UTC",
|
||||||
|
tm: time.Date(2077, time.April, 12, 23, 0, 0, 0, time.UTC),
|
||||||
|
want: "12 Apr 2077 at 23:00",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "UTC",
|
||||||
|
tm: time.Date(2025, time.March, 3, 2, 31, 0, 0, time.UTC),
|
||||||
|
want: "03 Mar 2025 at 02:31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Empty",
|
||||||
|
tm: time.Time{},
|
||||||
|
want: "",
|
||||||
|
},
|
||||||
|
// CET is one hour ahead of UTC but we print in UTC
|
||||||
|
{
|
||||||
|
name: "CET",
|
||||||
|
tm: time.Date(2024, 3, 17, 10, 15, 0, 0, time.FixedZone("CET", 1*60*60)),
|
||||||
|
want: "17 Mar 2024 at 09:15",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got := humanDate(test.tm)
|
||||||
|
|
||||||
|
assert.Equal(t, got, test.want)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue