-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathint64_test.go
49 lines (41 loc) · 939 Bytes
/
int64_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
package pgsql_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/acoshift/pgsql"
)
func TestNullInt64(t *testing.T) {
t.Parallel()
db := open(t)
defer db.Close()
_, err := db.Exec(`
drop table if exists test_pgsql_null_int64;
create table test_pgsql_null_int64 (
id int primary key,
value int
);
insert into test_pgsql_null_int64 (
id, value
) values
(0, 1),
(1, null);
`)
if !assert.NoError(t, err) {
return
}
defer db.Exec(`drop table test_pgsql_null_int64`)
t.Run("Scan", func(t *testing.T) {
{
var p int64
err = db.QueryRow(`select value from test_pgsql_null_int64 where id = 0`).Scan(pgsql.NullInt64(&p))
assert.NoError(t, err)
assert.Equal(t, int64(1), p)
}
{
var p int64
err = db.QueryRow(`select value from test_pgsql_null_int64 where id = 1`).Scan(pgsql.NullInt64(&p))
assert.NoError(t, err)
assert.Equal(t, int64(0), p)
}
})
}