forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
39 lines (32 loc) · 817 Bytes
/
time_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
package helix
import (
"encoding/json"
"testing"
)
type timeTest struct {
T Time `json:"started_at"`
}
func TestUnmarshalJSON(t *testing.T) {
t.Parallel()
testCases := []struct {
expectZero bool
testStr string
datetimeValue string
}{
{true, "", ""},
{true, "null", ""},
{false, "2018-02-05T08:15:59Z", "2018-02-05 08:15:59 +0000 UTC"},
}
for _, testCase := range testCases {
tme := &timeTest{}
json.Unmarshal([]byte(`{"started_at": "`+testCase.testStr+`"}`), tme)
if !tme.T.IsZero() {
if tme.T.Time.String() != testCase.datetimeValue {
t.Errorf("expected time to be \"%s\", got \"%s\"", testCase.datetimeValue, tme.T.Time.String())
}
}
if testCase.expectZero && !tme.T.IsZero() {
t.Errorf("expected zero value for time, got \"%s\"", tme.T.String())
}
}
}