github.com/jackc/pgx/v5@v5.5.5/pgtype/line_test.go (about) 1 package pgtype_test 2 3 import ( 4 "context" 5 "testing" 6 7 pgx "github.com/jackc/pgx/v5" 8 "github.com/jackc/pgx/v5/pgtype" 9 "github.com/jackc/pgx/v5/pgxtest" 10 ) 11 12 func TestLineTranscode(t *testing.T) { 13 ctr := defaultConnTestRunner 14 ctr.AfterConnect = func(ctx context.Context, t testing.TB, conn *pgx.Conn) { 15 pgxtest.SkipCockroachDB(t, conn, "Server does not support type line") 16 17 if _, ok := conn.TypeMap().TypeForName("line"); !ok { 18 t.Skip("Skipping due to no line type") 19 } 20 21 // line may exist but not be usable on 9.3 :( 22 var isPG93 bool 23 err := conn.QueryRow(context.Background(), "select version() ~ '9.3'").Scan(&isPG93) 24 if err != nil { 25 t.Fatal(err) 26 } 27 if isPG93 { 28 t.Skip("Skipping due to unimplemented line type in PG 9.3") 29 } 30 } 31 32 pgxtest.RunValueRoundTripTests(context.Background(), t, ctr, nil, "line", []pgxtest.ValueRoundTripTest{ 33 { 34 pgtype.Line{ 35 A: 1.23, B: 4.56, C: 7.89012345, 36 Valid: true, 37 }, 38 new(pgtype.Line), 39 isExpectedEq(pgtype.Line{ 40 A: 1.23, B: 4.56, C: 7.89012345, 41 Valid: true, 42 }), 43 }, 44 { 45 pgtype.Line{ 46 A: -1.23, B: -4.56, C: -7.89, 47 Valid: true, 48 }, 49 new(pgtype.Line), 50 isExpectedEq(pgtype.Line{ 51 A: -1.23, B: -4.56, C: -7.89, 52 Valid: true, 53 }), 54 }, 55 {pgtype.Line{}, new(pgtype.Line), isExpectedEq(pgtype.Line{})}, 56 {nil, new(pgtype.Line), isExpectedEq(pgtype.Line{})}, 57 }) 58 }