lets-go:14.1 assertion helper

This commit is contained in:
tamsin johnson 2024-02-13 12:23:57 -08:00
parent 52e1bbaa70
commit 6da4184eb0
2 changed files with 16 additions and 6 deletions

View File

@ -3,6 +3,8 @@ package main
import ( import (
"testing" "testing"
"time" "time"
"snippetbox.chaosfem.tw/internal/assert"
) )
func TestHumanDate(t *testing.T) { func TestHumanDate(t *testing.T) {
@ -26,16 +28,11 @@ func TestHumanDate(t *testing.T) {
tm: time.Date(2023, 3, 17, 10, 15, 0, 0, time.FixedZone("CET", 1*60*60)), tm: time.Date(2023, 3, 17, 10, 15, 0, 0, time.FixedZone("CET", 1*60*60)),
want: "17 Mar 2023 at 09:15", want: "17 Mar 2023 at 09:15",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
hd := humanDate(tt.tm) assert.Equal(t, humanDate(tt.tm), tt.want)
if hd != tt.want {
t.Errorf("got %q; want %q", hd, tt.want)
}
}) })
} }

View File

@ -0,0 +1,13 @@
package assert
import (
"testing"
)
func Equal[T comparable](t *testing.T, actual, expected T) {
t.Helper()
if actual != expected {
t.Errorf("got %v; want %v", actual, expected)
}
}