Test improvements.. I think

This commit is contained in:
Arran Ubels 2023-02-15 16:20:46 +11:00
parent 53a8cbdf09
commit 544b5426f4
No known key found for this signature in database
GPG Key ID: 135EDC7B21D17F48

View File

@ -10,7 +10,7 @@ import (
func TestOne(t *testing.T) { func TestOne(t *testing.T) {
time.Local = time.UTC time.Local = time.UTC
var ts time.Time = MustParse("2020-07-20+08:00") var ts = MustParse("2020-07-20+08:00")
assert.Equal(t, "2020-07-19 16:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) assert.Equal(t, "2020-07-19 16:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
} }
@ -435,6 +435,12 @@ func TestParse(t *testing.T) {
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
for _, th := range testInputs { for _, th := range testInputs {
t.Run(th.in, func(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fatalf("error: %s", r)
}
}()
if len(th.loc) > 0 { if len(th.loc) > 0 {
loc, err := time.LoadLocation(th.loc) loc, err := time.LoadLocation(th.loc)
if err != nil { if err != nil {
@ -447,16 +453,17 @@ func TestParse(t *testing.T) {
got := fmt.Sprintf("%v", ts.In(time.UTC)) got := fmt.Sprintf("%v", ts.In(time.UTC))
assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in) assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in)
if th.out != got { if th.out != got {
panic("whoops") t.Fatalf("whoops, got %s, expected %s", got, th.out)
} }
} else { } else {
ts = MustParse(th.in) ts = MustParse(th.in)
got := fmt.Sprintf("%v", ts.In(time.UTC)) got := fmt.Sprintf("%v", ts.In(time.UTC))
assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in) assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in)
if th.out != got { if th.out != got {
panic("whoops") t.Fatalf("whoops, got %s, expected %s", got, th.out)
} }
} }
})
} }
// some errors // some errors