-
Notifications
You must be signed in to change notification settings - Fork 6
/
string_test.go
48 lines (40 loc) · 977 Bytes
/
string_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
package pgsql_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/acoshift/pgsql"
)
func TestNullString(t *testing.T) {
t.Parallel()
db := open(t)
defer db.Close()
_, err := db.Exec(`
drop table if exists test_pgsql_null_string;
create table test_pgsql_null_string (
id int primary key,
value varchar
);
insert into test_pgsql_null_string (
id, value
) values
(0, 'hello'),
(1, null);
`)
require.NoError(t, err)
defer db.Exec(`drop table test_pgsql_null_string`)
t.Run("Scan", func(t *testing.T) {
{
var p string
err = db.QueryRow(`select value from test_pgsql_null_string where id = 0`).Scan(pgsql.NullString(&p))
require.NoError(t, err)
assert.Equal(t, "hello", p)
}
{
var p string
err = db.QueryRow(`select value from test_pgsql_null_string where id = 1`).Scan(pgsql.NullString(&p))
require.NoError(t, err)
assert.Equal(t, "", p)
}
})
}