-
Notifications
You must be signed in to change notification settings - Fork 0
/
int64_test.go
109 lines (91 loc) · 2.64 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package nulls
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
)
// TestNewInt64 tests NewInt64.
func TestNewInt64(t *testing.T) {
i := NewInt64(64)
assert.True(t, i.Valid, "should be valid")
assert.EqualValues(t, 64, i.Int64, "should contain correct value")
}
// Int64MarshalJSONSuite tests Int64.MarshalJSON.
type Int64MarshalJSONSuite struct {
suite.Suite
}
func (suite *Int64MarshalJSONSuite) TestNotValid() {
i := Int64{Int64: 64}
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(jsonNull, raw, "should return correct value")
}
func (suite *Int64MarshalJSONSuite) TestOK() {
i := NewInt64(64)
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(64), raw, "should return correct value")
}
func TestInt64_MarshalJSON(t *testing.T) {
suite.Run(t, new(Int64MarshalJSONSuite))
}
// Int64UnmarshalJSONSuite tests Int64.UnmarshalJSON.
type Int64UnmarshalJSONSuite struct {
suite.Suite
}
func (suite *Int64UnmarshalJSONSuite) TestNull() {
var i Int64
err := json.Unmarshal(jsonNull, &i)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *Int64UnmarshalJSONSuite) TestOK() {
var i Int64
err := json.Unmarshal(marshalMust(64), &i)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(64, i.Int64, "should unmarshal correct value")
}
func TestInt64_UnmarshalJSON(t *testing.T) {
suite.Run(t, new(Int64UnmarshalJSONSuite))
}
// Int64ScanSuite tests Int64.Scan.
type Int64ScanSuite struct {
suite.Suite
}
func (suite *Int64ScanSuite) TestNull() {
var i Int64
err := i.Scan(nil)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *Int64ScanSuite) TestOK() {
var i Int64
err := i.Scan(64)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(64, i.Int64, "should scan correct value")
}
func TestInt64_Scan(t *testing.T) {
suite.Run(t, new(Int64ScanSuite))
}
// Int64ValueSuite tests Int.Value.
type Int64ValueSuite struct {
suite.Suite
}
func (suite *Int64ValueSuite) TestNull() {
i := Int64{Int64: 64}
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.Nil(raw, "should return correct value")
}
func (suite *Int64ValueSuite) TestOK() {
i := NewInt64(64)
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.EqualValues(64, raw, "should return correct value")
}
func TestInt64_Value(t *testing.T) {
suite.Run(t, new(Int64ValueSuite))
}