-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimestamp_test.go
39 lines (34 loc) · 901 Bytes
/
timestamp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package zeronull_test
import (
"context"
"testing"
"time"
"github.com/jackc/pgx/v5/pgtype/zeronull"
"github.com/jackc/pgx/v5/pgxtest"
)
func isExpectedEqTimestamp(a any) func(any) bool {
return func(v any) bool {
at := time.Time(a.(zeronull.Timestamp))
vt := time.Time(v.(zeronull.Timestamp))
return at.Equal(vt)
}
}
func TestTimestampTranscode(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "timestamp", []pgxtest.ValueRoundTripTest{
{
(zeronull.Timestamp)(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)),
new(zeronull.Timestamp),
isExpectedEqTimestamp((zeronull.Timestamp)(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC))),
},
{
nil,
new(zeronull.Timestamp),
isExpectedEqTimestamp((zeronull.Timestamp)(time.Time{})),
},
{
(zeronull.Timestamp)(time.Time{}),
new(any),
isExpectedEq(nil),
},
})
}