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
package clock
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestSimpleClock_Now(t *testing.T) {
c := NewSimpleClock()
require.Equal(t, time.Unix(0, 0), c.Now())
expectedTime := time.Now()
c.v.Store(&expectedTime)
require.Equal(t, expectedTime, c.Now())
}
func TestSimpleClock_SetTime(t *testing.T) {
tests := []struct {
name string
expectedTime int64
}{
{
name: "SetZeroTime",
expectedTime: 0,
},
{
name: "SetZeroUnixTime",
expectedTime: time.Unix(0, 0).Unix(),
},
{
name: "SetCurrentTime",
expectedTime: time.Now().Unix(),
},
{
name: "SetFutureTime",
expectedTime: time.Now().Add(time.Hour).Unix(),
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
c := NewSimpleClock()
c.SetTime(uint64(test.expectedTime))
require.Equal(t, time.Unix(test.expectedTime, 0), c.Now())
})
}
}