-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbox3d_test.go
67 lines (58 loc) · 2.1 KB
/
box3d_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
package pgxgeos_test
import (
"context"
"testing"
"github.com/alecthomas/assert/v2"
"github.com/jackc/pgx/v5"
"github.com/twpayne/go-geos"
)
func TestBox3DCodecPointer(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
box3D := geos.NewBox3D(1, 2, 3, 4, 5, 6)
var actual geos.Box3D
assert.NoError(tb, conn.QueryRow(ctx, "select $1::box3d", box3D).Scan(&actual))
assert.Equal(tb, *box3D, actual)
})
}
func TestBox3DCodecPointerToPointer(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
box3D := geos.NewBox3D(1, 2, 3, 4, 5, 6)
var actual *geos.Box3D
assert.NoError(tb, conn.QueryRow(ctx, "select $1::box3d", box3D).Scan(&actual))
assert.Equal(tb, *box3D, *actual)
})
}
func TestBox3DCodecNull(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
actual := geos.NewBox3D(1, 2, 3, 4, 5, 6)
assert.NoError(tb, conn.QueryRow(ctx, "select NULL::box3d").Scan(&actual))
assert.Zero(tb, actual)
})
}
func TestBox3DCodecScan(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
original := geos.NewBox3D(1, 2, 3, 4, 5, 6)
rows, err := conn.Query(ctx, "select $1::box3d", original)
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err := rows.Values()
assert.NoError(t, err)
assert.Equal(t, 1, len(values))
assert.Equal(t, *original, *values[0].(*geos.Box3D))
assert.False(t, rows.Next())
assert.NoError(t, rows.Err())
})
}
func TestBox3DCodecValue(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
box3D := geos.Box3D{MinX: 1, MinY: 2, MinZ: 3, MaxX: 4, MaxY: 5, MaxZ: 6}
var actual geos.Box3D
assert.NoError(tb, conn.QueryRow(ctx, "select $1::box3d", box3D).Scan(&actual))
assert.Equal(tb, box3D, actual)
})
}