-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtime_test.go
64 lines (48 loc) · 1.52 KB
/
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
56
57
58
59
60
61
62
63
64
package logf
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRFC3339TimeEncoder(t *testing.T) {
tm := time.Unix(1542266559, 305941000).UTC()
enc := testTypeEncoder{}
RFC3339TimeEncoder(tm, &enc)
assert.EqualValues(t, "2018-11-15T07:22:39Z", enc.result)
}
func TestRFC3339NanoTimeEncoder(t *testing.T) {
tm := time.Unix(1542266559, 305941000).UTC()
enc := testTypeEncoder{}
RFC3339NanoTimeEncoder(tm, &enc)
assert.EqualValues(t, "2018-11-15T07:22:39.305941Z", enc.result)
}
func TestLayoutTimeEncoder(t *testing.T) {
tm := time.Unix(1542266559, 305941000).UTC()
enc := testTypeEncoder{}
LayoutTimeEncoder(time.StampNano)(tm, &enc)
assert.EqualValues(t, "Nov 15 07:22:39.305941000", enc.result)
}
func TestUnixNanoTimeEncoder(t *testing.T) {
tm := time.Unix(1542266559, 305941000).UTC()
enc := testTypeEncoder{}
UnixNanoTimeEncoder(tm, &enc)
assert.EqualValues(t, 1542266559305941000, enc.result)
}
func TestNanoDurationEncoder(t *testing.T) {
d := time.Duration(66559305941000)
enc := testTypeEncoder{}
NanoDurationEncoder(d, &enc)
assert.EqualValues(t, 66559305941000, enc.result)
}
func TestFloatSecondsDurationEncoder(t *testing.T) {
d := time.Duration(66559305941000)
enc := testTypeEncoder{}
FloatSecondsDurationEncoder(d, &enc)
assert.InDelta(t, 66559.305941, enc.result, 0.0000005)
}
func TestStringDurationEncoder(t *testing.T) {
d := time.Duration(66559305941000)
enc := testTypeEncoder{}
StringDurationEncoder(d, &enc)
assert.EqualValues(t, "18h29m19.305941s", enc.result)
}