-
Notifications
You must be signed in to change notification settings - Fork 0
/
jumper_test.go
61 lines (45 loc) · 1.04 KB
/
jumper_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
// +build !race
package timejumper
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestJumperClock_Now(t *testing.T) {
t.Parallel()
sleepTime := 10 * time.Millisecond
t.Run("frozen behavior", func(t *testing.T) {
c := New()
present := time.Now()
c.Freeze(present)
time.Sleep(sleepTime)
future := c.Now()
assert.Equal(t, present, future)
})
t.Run("scaling behavior", func(t *testing.T) {
c := New()
present := time.Now()
c.Freeze(present)
scale := 2
c.Scale(scale)
c.Sleep(sleepTime)
future := c.Now()
expectedDiff := sleepTime * time.Duration(scale)
assert.Equal(t, expectedDiff, future.Sub(present))
})
t.Run("jumping behavior", func(t *testing.T) {
c := New()
present := time.Now()
c.Freeze(present)
future := present.AddDate(1, 0, 0)
c.Jump(future)
assert.Equal(t, future, c.Now())
})
t.Run("sleeping behavior", func(t *testing.T) {
c := New()
present := time.Now()
c.Freeze(present)
c.Sleep(sleepTime)
assert.Equal(t, present.Add(sleepTime), c.Now())
})
}