File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,31 @@ type NullBool struct {
5858 sql.NullBool
5959}
6060
61+ // NullStringFrom creates a valid NullString
62+ func NullStringFrom (v string ) NullString {
63+ return NullString {sql.NullString {v , true }}
64+ }
65+
66+ // NullFloat64From creates a valid NullFloat64
67+ func NullFloat64From (v float64 ) NullFloat64 {
68+ return NullFloat64 {sql.NullFloat64 {v , true }}
69+ }
70+
71+ // NullInt64From creates a valid NullInt64
72+ func NullInt64From (v int64 ) NullInt64 {
73+ return NullInt64 {sql.NullInt64 {v , true }}
74+ }
75+
76+ // NullTimeFrom creates a valid NullTime
77+ func NullTimeFrom (v time.Time ) NullTime {
78+ return NullTime {pq.NullTime {v , true }}
79+ }
80+
81+ // NullBoolFrom creates a valid NullBool
82+ func NullBoolFrom (v bool ) NullBool {
83+ return NullBool {sql.NullBool {v , true }}
84+ }
85+
6186var nullString = []byte ("null" )
6287
6388// MarshalJSON correctly serializes a NullString to JSON
Original file line number Diff line number Diff line change 1+ package dat
2+
3+ import (
4+ "testing"
5+ "time"
6+
7+ "gopkg.in/stretchr/testify.v1/assert"
8+ )
9+
10+ func TestNullStringFrom (t * testing.T ) {
11+ v := "foo"
12+ n := NullStringFrom (v )
13+
14+ assert .True (t , n .Valid )
15+ assert .Equal (t , n .String , v )
16+ }
17+
18+ func TestNullFloat64From (t * testing.T ) {
19+ v := 42.2
20+ n := NullFloat64From (v )
21+
22+ assert .True (t , n .Valid )
23+ assert .Equal (t , n .Float64 , v )
24+ }
25+
26+ func TestNullInt64From (t * testing.T ) {
27+ v := int64 (400 )
28+ n := NullInt64From (v )
29+
30+ assert .True (t , n .Valid )
31+ assert .Equal (t , n .Int64 , v )
32+ }
33+
34+ func TestNullTimeFrom (t * testing.T ) {
35+ v := time .Now ()
36+ n := NullTimeFrom (v )
37+
38+ assert .True (t , n .Valid )
39+ assert .Equal (t , n .Time , v )
40+ }
41+
42+ func TestNullBoolFrom (t * testing.T ) {
43+ v := false
44+ n := NullBoolFrom (v )
45+
46+ assert .True (t , n .Valid )
47+ assert .Equal (t , n .Bool , v )
48+ }
You can’t perform that action at this time.
0 commit comments