diff --git a/snippetbox/cmd/web/templates_test.go b/snippetbox/cmd/web/templates_test.go index d65a3df..a0aed7a 100644 --- a/snippetbox/cmd/web/templates_test.go +++ b/snippetbox/cmd/web/templates_test.go @@ -3,6 +3,8 @@ package main import ( "testing" "time" + + "snippetbox.chaosfem.tw/internal/assert" ) 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)), want: "17 Mar 2023 at 09:15", }, - } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - hd := humanDate(tt.tm) - - if hd != tt.want { - t.Errorf("got %q; want %q", hd, tt.want) - } + assert.Equal(t, humanDate(tt.tm), tt.want) }) } diff --git a/snippetbox/internal/assert/assert.go b/snippetbox/internal/assert/assert.go new file mode 100644 index 0000000..fe81eb7 --- /dev/null +++ b/snippetbox/internal/assert/assert.go @@ -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) + } +}