-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpartial_msg_test.go
52 lines (48 loc) · 1.11 KB
/
partial_msg_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
package f3
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_roundDownToUnixTime(t *testing.T) {
someTime, err := time.Parse(time.RFC3339Nano, "2024-03-07T15:06:20.522847852Z")
require.NoError(t, err)
for _, test := range []struct {
name string
at time.Time
interval time.Duration
want int64
}{
{
name: "millisecond",
at: someTime,
interval: time.Millisecond * 200,
want: 1709823980400, // 2024-03-07 15:06:20.4
},
{
name: "second",
at: someTime,
interval: time.Second * 7,
want: 1709823976000, // 2024-03-07 15:06:16
},
{
name: "bigBang",
at: time.Unix(0, 0),
interval: time.Second * 7,
want: 0,
},
{
name: "justAfterBigBang",
at: time.Unix(5, 0),
interval: time.Second * 5,
want: 5000,
},
} {
t.Run(test.name, func(t *testing.T) {
got := roundDownToUnixMilliTime(test.at, test.interval)
require.Equal(t, test.want, got)
require.GreaterOrEqual(t, got, time.Microsecond.Milliseconds())
require.LessOrEqual(t, got, test.at.UnixMilli())
})
}
}