@@ -22,7 +22,7 @@ func TestTime_ImplementsUnmarshaler(t *testing.T) {
22
22
}
23
23
24
24
func TestTime_ImplementsGraphQLType (t * testing.T ) {
25
- gt := new ( Time )
25
+ gt := & Time {}
26
26
27
27
if gt .ImplementsGraphQLType ("foobar" ) {
28
28
t .Error ("Type *Time must not claim to implement GraphQL type 'foobar'" )
@@ -36,7 +36,7 @@ func TestTime_ImplementsGraphQLType(t *testing.T) {
36
36
func TestTime_MarshalJSON (t * testing.T ) {
37
37
var err error
38
38
var b1 , b2 []byte
39
- ref := time .Date (2021 , time .April , 20 , 12 , 3 , 23 , 0 , time .UTC )
39
+ ref := time .Date (2021 , time .April , 20 , 12 , 3 , 23 , 551476231 , time .UTC )
40
40
41
41
if b1 , err = json .Marshal (ref ); err != nil {
42
42
t .Error (err )
@@ -57,8 +57,8 @@ func TestTime_UnmarshalGraphQL(t *testing.T) {
57
57
type args struct {
58
58
input interface {}
59
59
}
60
-
61
- ref := time .Date ( 2021 , time . April , 20 , 12 , 3 , 23 , 0 , time . UTC )
60
+ ref := time . Date ( 2021 , time . April , 20 , 12 , 3 , 23 , 551476231 , time . UTC )
61
+ refZeroNano := time .Unix ( ref . Unix (), 0 )
62
62
63
63
t .Run ("invalid" , func (t * testing.T ) {
64
64
tests := []struct {
@@ -111,46 +111,52 @@ func TestTime_UnmarshalGraphQL(t *testing.T) {
111
111
args : args {
112
112
input : ref .Format (time .RFC3339 ),
113
113
},
114
- wantEq : ref ,
114
+ wantEq : refZeroNano ,
115
115
},
116
116
{
117
117
name : "bytes" ,
118
118
args : args {
119
119
input : []byte (ref .Format (time .RFC3339 )),
120
120
},
121
- wantEq : ref ,
121
+ wantEq : refZeroNano ,
122
122
},
123
123
{
124
124
name : "int32" ,
125
125
args : args {
126
126
input : int32 (ref .Unix ()),
127
127
},
128
- wantEq : ref ,
128
+ wantEq : refZeroNano ,
129
129
},
130
130
{
131
131
name : "int64" ,
132
132
args : args {
133
133
input : ref .Unix (),
134
134
},
135
+ wantEq : refZeroNano ,
136
+ },
137
+ {
138
+ name : "int64-nano" ,
139
+ args : args {
140
+ input : ref .UnixNano (),
141
+ },
135
142
wantEq : ref ,
136
143
},
137
144
{
138
145
name : "float64" ,
139
146
args : args {
140
147
input : float64 (ref .Unix ()),
141
148
},
142
- wantEq : ref ,
149
+ wantEq : refZeroNano ,
143
150
},
144
151
}
145
152
146
153
for _ , tt := range tests {
147
154
t .Run (tt .name , func (t * testing.T ) {
148
- gt := new ( Time )
155
+ gt := & Time {}
149
156
if err := gt .UnmarshalGraphQL (tt .args .input ); err != nil {
150
157
t .Errorf ("UnmarshalGraphQL() error = %v" , err )
151
158
return
152
159
}
153
-
154
160
if ! gt .Equal (tt .wantEq ) {
155
161
t .Errorf ("UnmarshalGraphQL() got = %v, want = %v" , gt , tt .wantEq )
156
162
}
0 commit comments