lets-go:14.1 assertion helper
This commit is contained in:
parent
52e1bbaa70
commit
6da4184eb0
@ -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)
|
||||
})
|
||||
|
||||
}
|
||||
|
13
snippetbox/internal/assert/assert.go
Normal file
13
snippetbox/internal/assert/assert.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user