666af9ead5
Though this doesn't follow Go naming conventions exactly it makes names more consistent with PostgreSQL and it is easier to read. For example, TIDOID becomes TidOid. In addition this is one less breaking change in the move to V3.
152 lines
4.2 KiB
Go
152 lines
4.2 KiB
Go
package pgtype_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/pgtype"
|
|
)
|
|
|
|
func TestAclitemArrayTranscode(t *testing.T) {
|
|
testSuccessfulTranscode(t, "aclitem[]", []interface{}{
|
|
&pgtype.AclitemArray{
|
|
Elements: nil,
|
|
Dimensions: nil,
|
|
Status: pgtype.Present,
|
|
},
|
|
&pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{
|
|
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{Status: pgtype.Null},
|
|
},
|
|
Dimensions: []pgtype.ArrayDimension{{Length: 2, LowerBound: 1}},
|
|
Status: pgtype.Present,
|
|
},
|
|
&pgtype.AclitemArray{Status: pgtype.Null},
|
|
&pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{
|
|
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{String: `postgres=arwdDxt/" tricky, ' } "" \ test user "`, Status: pgtype.Present},
|
|
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{Status: pgtype.Null},
|
|
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
|
|
},
|
|
Dimensions: []pgtype.ArrayDimension{{Length: 3, LowerBound: 1}, {Length: 2, LowerBound: 1}},
|
|
Status: pgtype.Present,
|
|
},
|
|
&pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{
|
|
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
|
|
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
|
|
},
|
|
Dimensions: []pgtype.ArrayDimension{
|
|
{Length: 2, LowerBound: 4},
|
|
{Length: 2, LowerBound: 2},
|
|
},
|
|
Status: pgtype.Present,
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAclitemArrayConvertFrom(t *testing.T) {
|
|
successfulTests := []struct {
|
|
source interface{}
|
|
result pgtype.AclitemArray
|
|
}{
|
|
{
|
|
source: []string{"=r/postgres"},
|
|
result: pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{{String: "=r/postgres", Status: pgtype.Present}},
|
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
|
Status: pgtype.Present},
|
|
},
|
|
{
|
|
source: (([]string)(nil)),
|
|
result: pgtype.AclitemArray{Status: pgtype.Null},
|
|
},
|
|
}
|
|
|
|
for i, tt := range successfulTests {
|
|
var r pgtype.AclitemArray
|
|
err := r.ConvertFrom(tt.source)
|
|
if err != nil {
|
|
t.Errorf("%d: %v", i, err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(r, tt.result) {
|
|
t.Errorf("%d: expected %v to convert to %v, but it was %v", i, tt.source, tt.result, r)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAclitemArrayAssignTo(t *testing.T) {
|
|
var stringSlice []string
|
|
type _stringSlice []string
|
|
var namedStringSlice _stringSlice
|
|
|
|
simpleTests := []struct {
|
|
src pgtype.AclitemArray
|
|
dst interface{}
|
|
expected interface{}
|
|
}{
|
|
{
|
|
src: pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{{String: "=r/postgres", Status: pgtype.Present}},
|
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
|
Status: pgtype.Present,
|
|
},
|
|
dst: &stringSlice,
|
|
expected: []string{"=r/postgres"},
|
|
},
|
|
{
|
|
src: pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{{String: "=r/postgres", Status: pgtype.Present}},
|
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
|
Status: pgtype.Present,
|
|
},
|
|
dst: &namedStringSlice,
|
|
expected: _stringSlice{"=r/postgres"},
|
|
},
|
|
{
|
|
src: pgtype.AclitemArray{Status: pgtype.Null},
|
|
dst: &stringSlice,
|
|
expected: (([]string)(nil)),
|
|
},
|
|
}
|
|
|
|
for i, tt := range simpleTests {
|
|
err := tt.src.AssignTo(tt.dst)
|
|
if err != nil {
|
|
t.Errorf("%d: %v", i, err)
|
|
}
|
|
|
|
if dst := reflect.ValueOf(tt.dst).Elem().Interface(); !reflect.DeepEqual(dst, tt.expected) {
|
|
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
|
|
}
|
|
}
|
|
|
|
errorTests := []struct {
|
|
src pgtype.AclitemArray
|
|
dst interface{}
|
|
}{
|
|
{
|
|
src: pgtype.AclitemArray{
|
|
Elements: []pgtype.Aclitem{{Status: pgtype.Null}},
|
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
|
Status: pgtype.Present,
|
|
},
|
|
dst: &stringSlice,
|
|
},
|
|
}
|
|
|
|
for i, tt := range errorTests {
|
|
err := tt.src.AssignTo(tt.dst)
|
|
if err == nil {
|
|
t.Errorf("%d: expected error but none was returned (%v -> %v)", i, tt.src, tt.dst)
|
|
}
|
|
}
|
|
}
|