mirror of https://github.com/jackc/pgx.git
34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
package pgtype_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgxtest"
|
|
)
|
|
|
|
func TestJSONBTranscode(t *testing.T) {
|
|
type jsonStruct struct {
|
|
Name string `json:"name"`
|
|
Age int `json:"age"`
|
|
}
|
|
|
|
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "jsonb", []pgxtest.ValueRoundTripTest{
|
|
{nil, new(*jsonStruct), isExpectedEq((*jsonStruct)(nil))},
|
|
{map[string]any(nil), new(*string), isExpectedEq((*string)(nil))},
|
|
{map[string]any(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
|
|
{[]byte(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
|
|
{nil, new([]byte), isExpectedEqBytes([]byte(nil))},
|
|
})
|
|
|
|
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, pgxtest.KnownOIDQueryExecModes, "jsonb", []pgxtest.ValueRoundTripTest{
|
|
{[]byte("{}"), new([]byte), isExpectedEqBytes([]byte("{}"))},
|
|
{[]byte("null"), new([]byte), isExpectedEqBytes([]byte("null"))},
|
|
{[]byte("42"), new([]byte), isExpectedEqBytes([]byte("42"))},
|
|
{[]byte(`"hello"`), new([]byte), isExpectedEqBytes([]byte(`"hello"`))},
|
|
{[]byte(`"hello"`), new(string), isExpectedEq(`"hello"`)},
|
|
{map[string]any{"foo": "bar"}, new(map[string]any), isExpectedEqMap(map[string]any{"foo": "bar"})},
|
|
{jsonStruct{Name: "Adam", Age: 10}, new(jsonStruct), isExpectedEq(jsonStruct{Name: "Adam", Age: 10})},
|
|
})
|
|
}
|