-
Notifications
You must be signed in to change notification settings - Fork 2
/
null_int64_test.go
48 lines (44 loc) · 1.21 KB
/
null_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
package gosql_test
import (
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/twharmon/gosql"
)
func TestNullInt64Valid(t *testing.T) {
db, mock, err := getMockDB()
check(t, err)
type T struct {
ID int `idx:"primary"`
Name gosql.NullInt64
}
control := T{
ID: 5,
Name: gosql.NullInt64{Valid: true, Int64: 5},
}
rows := sqlmock.NewRows([]string{"id", "name"})
rows.AddRow(control.ID, control.Name)
mock.ExpectQuery(`^select \* from t where id = \? limit 1$`).WithArgs(control.ID).WillReturnRows(rows)
var test T
check(t, db.Select("*").Where("id = ?", control.ID).Get(&test))
check(t, mock.ExpectationsWereMet())
equals(t, control, test)
}
func TestNullInt64NotValid(t *testing.T) {
db, mock, err := getMockDB()
check(t, err)
type T struct {
ID int `idx:"primary"`
Name gosql.NullInt64
}
control := T{
ID: 5,
Name: gosql.NullInt64{Valid: false},
}
rows := sqlmock.NewRows([]string{"id", "name"})
rows.AddRow(control.ID, control.Name)
mock.ExpectQuery(`^select \* from t where id = \? limit 1$`).WithArgs(control.ID).WillReturnRows(rows)
var test T
check(t, db.Select("*").Where("id = ?", control.ID).Get(&test))
check(t, mock.ExpectationsWereMet())
equals(t, control, test)
}