support binding of []int type to array integer
This commit is contained in:
committed by
Jack Christensen
parent
f9440700e5
commit
738f3a1027
+23
-2
@@ -1,6 +1,7 @@
|
||||
package pgtype_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -54,8 +55,9 @@ func TestInt4ArrayTranscode(t *testing.T) {
|
||||
|
||||
func TestInt4ArraySet(t *testing.T) {
|
||||
successfulTests := []struct {
|
||||
source interface{}
|
||||
result pgtype.Int4Array
|
||||
source interface{}
|
||||
result pgtype.Int4Array
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
source: []int32{1},
|
||||
@@ -64,6 +66,17 @@ func TestInt4ArraySet(t *testing.T) {
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: []int{1},
|
||||
result: pgtype.Int4Array{
|
||||
Elements: []pgtype.Int4{{Int: 1, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: []int{1, math.MaxInt32 + 1, 2},
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
source: []uint32{1},
|
||||
result: pgtype.Int4Array{
|
||||
@@ -81,9 +94,17 @@ func TestInt4ArraySet(t *testing.T) {
|
||||
var r pgtype.Int4Array
|
||||
err := r.Set(tt.source)
|
||||
if err != nil {
|
||||
if tt.expectedError {
|
||||
continue
|
||||
}
|
||||
t.Errorf("%d: %v", i, err)
|
||||
}
|
||||
|
||||
if tt.expectedError {
|
||||
t.Errorf("%d: an error was expected, %v", i, tt)
|
||||
continue
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user