You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ratchet/internal/server/templates_test.go

50 lines
876 B
Go

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)
})
}
}