-
Notifications
You must be signed in to change notification settings - Fork 911
/
conn_go19_test.go
83 lines (74 loc) · 1.38 KB
/
conn_go19_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//go:build go1.9
// +build go1.9
package pq
import (
"fmt"
"reflect"
"testing"
)
func TestArrayArg(t *testing.T) {
db := openTestConn(t)
defer db.Close()
for _, tc := range []struct {
pgType string
in, out interface{}
}{
{
pgType: "int[]",
in: []int{245, 231},
out: []int64{245, 231},
},
{
pgType: "int[]",
in: &[]int{245, 231},
out: []int64{245, 231},
},
{
pgType: "int[]",
in: []int64{245, 231},
},
{
pgType: "int[]",
in: &[]int64{245, 231},
out: []int64{245, 231},
},
{
pgType: "varchar[]",
in: []string{"hello", "world"},
},
{
pgType: "varchar[]",
in: &[]string{"hello", "world"},
out: []string{"hello", "world"},
},
} {
if tc.out == nil {
tc.out = tc.in
}
t.Run(fmt.Sprintf("%#v", tc.in), func(t *testing.T) {
r, err := db.Query(fmt.Sprintf("SELECT $1::%s", tc.pgType), tc.in)
if err != nil {
t.Fatal(err)
}
defer r.Close()
if !r.Next() {
if r.Err() != nil {
t.Fatal(r.Err())
}
t.Fatal("expected row")
}
defer func() {
if r.Next() {
t.Fatal("unexpected row")
}
}()
got := reflect.New(reflect.TypeOf(tc.out))
if err := r.Scan(Array(got.Interface())); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(tc.out, got.Elem().Interface()) {
t.Errorf("got %v, want %v", got, tc.out)
}
})
}
}