-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
time_test.go
41 lines (33 loc) · 932 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
40
41
package mono
import (
"encoding/json"
"testing"
"time"
)
func TestTime_UnmarshalJSON(t *testing.T) {
jsonString := []byte(`{"time": 1583000643}`)
expectedData := struct{ Time Time }{
Time: Time{time.Date(2020, 2, 29, 18, 24, 03, 00, time.UTC)},
}
var actualData struct{ Time Time }
err := json.Unmarshal(jsonString, &actualData)
if err != nil {
t.Errorf("expected error: nil, actual error: %v", err)
}
assertEqual(t, expectedData, actualData)
}
func TestTime_MarshalJson(t *testing.T) {
transactionData := struct {
Time Time `json:"time"`
}{
Time: Time{time.Date(2020, 2, 29, 18, 24, 03, 00, time.UTC)},
}
expectedJson := `{"time":1583000643}`
actualJson, err := json.Marshal(&transactionData)
if err != nil {
t.Errorf("expected error: nil, actual error: %v", err)
}
if expectedJson != string(actualJson) {
t.Errorf("expected data: %v, actual data: %v", expectedJson, string(actualJson))
}
}