-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
kitchen_time_test.go
55 lines (46 loc) · 1.28 KB
/
kitchen_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package jsonx
import (
"encoding/json"
"testing"
"time"
)
func TestJSONKitchenTime(t *testing.T) {
tests := []struct {
rawData string
}{
{
rawData: `{"start": "8:33 AM", "end": "3:04 PM", "nothing": null, "empty": ""}`,
},
{
rawData: `{"start": "08:33 AM", "end": "03:04 PM", "nothing": null, "empty": ""}`,
},
{
rawData: `{"start": "08:33:00.000000 AM", "end": "03:04 PM", "nothing": null, "empty": ""}`,
},
}
for _, tt := range tests {
v := struct {
Start KitchenTime `json:"start"`
End KitchenTime `json:"end"`
Nothing KitchenTime `json:"nothing"`
Empty KitchenTime `json:"empty"`
}{}
err := json.Unmarshal([]byte(tt.rawData), &v)
if err != nil {
t.Fatal(err)
}
if !v.Nothing.IsZero() {
t.Fatalf("expected 'nothing' to be zero but got: %v", v.Nothing)
}
if !v.Empty.IsZero() {
t.Fatalf("expected 'empty' to be zero but got: %v", v.Empty)
}
loc := time.UTC
if expected, got := time.Date(0, time.January, 1, 8, 33, 0, 0, loc), v.Start.Value(); expected != got {
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
}
if expected, got := time.Date(0, time.January, 1, 15, 4, 0, 0, loc), v.End.Value(); expected != got {
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
}
}
}