2021-11-06 19:25:25 +01:00
|
|
|
package jsonx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2022-02-18 21:19:33 +01:00
|
|
|
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": ""}`,
|
|
|
|
},
|
2021-11-06 19:25:25 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 21:19:33 +01:00
|
|
|
for _, tt := range tests {
|
|
|
|
v := struct {
|
|
|
|
Start KitchenTime `json:"start"`
|
|
|
|
End KitchenTime `json:"end"`
|
|
|
|
Nothing KitchenTime `json:"nothing"`
|
|
|
|
Empty KitchenTime `json:"empty"`
|
|
|
|
}{}
|
2021-11-06 19:25:25 +01:00
|
|
|
|
2022-02-18 21:19:33 +01:00
|
|
|
err := json.Unmarshal([]byte(tt.rawData), &v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-11-06 19:25:25 +01:00
|
|
|
|
2022-02-18 21:19:33 +01:00
|
|
|
if !v.Nothing.IsZero() {
|
|
|
|
t.Fatalf("expected 'nothing' to be zero but got: %v", v.Nothing)
|
|
|
|
}
|
2021-11-06 19:25:25 +01:00
|
|
|
|
2022-02-18 21:19:33 +01:00
|
|
|
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)
|
|
|
|
}
|
2021-11-06 19:25:25 +01:00
|
|
|
|
2022-02-18 21:19:33 +01:00
|
|
|
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)
|
|
|
|
}
|
2021-11-06 19:25:25 +01:00
|
|
|
}
|
|
|
|
}
|