-
Notifications
You must be signed in to change notification settings - Fork 4
/
timestamp_test.go
37 lines (30 loc) · 940 Bytes
/
timestamp_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
package patrol
import (
"encoding/json"
"log"
"sabey.co/unittest"
"testing"
"time"
)
func TestTimestamp(t *testing.T) {
log.Println("TestTimestamp")
ts := &Timestamp{}
unittest.IsNil(t, json.Unmarshal([]byte("\"\""), ts))
unittest.Equals(t, ts.IsZero(), true)
ts = &Timestamp{}
unittest.IsNil(t, json.Unmarshal([]byte("\"null\""), ts))
unittest.Equals(t, ts.IsZero(), true)
ts = &Timestamp{}
unittest.IsNil(t, json.Unmarshal([]byte("null"), ts))
unittest.Equals(t, ts.IsZero(), true)
ts = &Timestamp{}
now := time.Now()
unittest.IsNil(t, json.Unmarshal([]byte("\""+now.Format(time.RFC3339)+"\""), ts))
unittest.Equals(t, ts.Time.Format(time.RFC3339), now.Format(time.RFC3339))
ts = &Timestamp{
TimestampFormat: time.UnixDate,
}
now = time.Now()
unittest.IsNil(t, json.Unmarshal([]byte("\""+now.Format(time.UnixDate)+"\""), ts))
unittest.Equals(t, ts.Time.Format(time.UnixDate), now.Format(time.UnixDate))
}