github.com/jackc/pgx/v5@v5.5.5/pgtype/zeronull/timestamptz_test.go (about)

     1  package zeronull_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/jackc/pgx/v5/pgtype/zeronull"
     9  	"github.com/jackc/pgx/v5/pgxtest"
    10  )
    11  
    12  func isExpectedEqTimestamptz(a any) func(any) bool {
    13  	return func(v any) bool {
    14  		at := time.Time(a.(zeronull.Timestamptz))
    15  		vt := time.Time(v.(zeronull.Timestamptz))
    16  
    17  		return at.Equal(vt)
    18  	}
    19  }
    20  
    21  func TestTimestamptzTranscode(t *testing.T) {
    22  	pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "timestamptz", []pgxtest.ValueRoundTripTest{
    23  		{
    24  			(zeronull.Timestamptz)(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)),
    25  			new(zeronull.Timestamptz),
    26  			isExpectedEqTimestamptz((zeronull.Timestamptz)(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC))),
    27  		},
    28  		{
    29  			nil,
    30  			new(zeronull.Timestamptz),
    31  			isExpectedEqTimestamptz((zeronull.Timestamptz)(time.Time{})),
    32  		},
    33  		{
    34  			(zeronull.Timestamptz)(time.Time{}),
    35  			new(any),
    36  			isExpectedEq(nil),
    37  		},
    38  	})
    39  }