mirror of https://github.com/jackc/pgx.git
More transcoding type tests
Text every combination of text and binary arguments and text and binary results.pull/483/head
parent
2a55a4048a
commit
6c0de9ff37
|
@ -107,7 +107,7 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []
|
||||||
conn := MustConnectPgx(t)
|
conn := MustConnectPgx(t)
|
||||||
defer MustCloseContext(t, conn)
|
defer MustCloseContext(t, conn)
|
||||||
|
|
||||||
ps, err := conn.Prepare("test", fmt.Sprintf("select $1::%s", pgTypeName))
|
_, err := conn.Prepare("test", fmt.Sprintf("select $1::%s", pgTypeName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -121,29 +121,43 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, v := range values {
|
for i, v := range values {
|
||||||
for _, fc := range formats {
|
for _, paramFormat := range formats {
|
||||||
ps.FieldDescriptions[0].FormatCode = fc.formatCode
|
for _, resultFormat := range formats {
|
||||||
vEncoder := ForceEncoder(v, fc.formatCode)
|
vEncoder := ForceEncoder(v, paramFormat.formatCode)
|
||||||
if vEncoder == nil {
|
if vEncoder == nil {
|
||||||
t.Logf("Skipping: %#v does not implement %v", v, fc.name)
|
t.Logf("Skipping Param %s Result %s: %#v does not implement %v for encoding", paramFormat.name, resultFormat.name, v, paramFormat.name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Derefence value if it is a pointer
|
switch resultFormat.formatCode {
|
||||||
derefV := v
|
case pgx.TextFormatCode:
|
||||||
refVal := reflect.ValueOf(v)
|
if _, ok := v.(pgtype.TextEncoder); !ok {
|
||||||
if refVal.Kind() == reflect.Ptr {
|
t.Logf("Skipping Param %s Result %s: %#v does not implement %v for decoding", paramFormat.name, resultFormat.name, v, resultFormat.name)
|
||||||
derefV = refVal.Elem().Interface()
|
continue
|
||||||
}
|
}
|
||||||
|
case pgx.BinaryFormatCode:
|
||||||
|
if _, ok := v.(pgtype.BinaryEncoder); !ok {
|
||||||
|
t.Logf("Skipping Param %s Result %s: %#v does not implement %v for decoding", paramFormat.name, resultFormat.name, v, resultFormat.name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result := reflect.New(reflect.TypeOf(derefV))
|
// Derefence value if it is a pointer
|
||||||
|
derefV := v
|
||||||
|
refVal := reflect.ValueOf(v)
|
||||||
|
if refVal.Kind() == reflect.Ptr {
|
||||||
|
derefV = refVal.Elem().Interface()
|
||||||
|
}
|
||||||
|
|
||||||
err := conn.QueryRow(context.Background(), "test", vEncoder).Scan(result.Interface())
|
result := reflect.New(reflect.TypeOf(derefV))
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%v %d: %v", fc.name, i, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !eqFunc(result.Elem().Interface(), derefV) {
|
err := conn.QueryRow(context.Background(), "test", pgx.QueryResultFormats{resultFormat.formatCode}, vEncoder).Scan(result.Interface())
|
||||||
t.Errorf("%v %d: expected %v, got %v", fc.name, i, derefV, result.Elem().Interface())
|
if err != nil {
|
||||||
|
t.Errorf("Param %s Result %s %d: %v", paramFormat.name, resultFormat.name, i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !eqFunc(result.Elem().Interface(), derefV) {
|
||||||
|
t.Errorf("Param %s Result %s %d: expected %v, got %v", paramFormat.name, resultFormat.name, i, derefV, result.Elem().Interface())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue