summaryrefslogtreecommitdiff
path: root/internal/clock/fixed_test.go
blob: 5171bd6ca6bcdcecc3901f1905849a9151233a28 (plain)
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
package clock

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestTestingClock(t *testing.T) {
	c := &Fixed{
		now: time.Unix(0, 0),
	}

	assert.Equal(t, int64(0), c.Now().Unix())
	c.now = time.Unix(20, 0)

	assert.Equal(t, int64(20), c.Now().Unix())
	assert.Equal(t, int64(20000000000), c.Now().UnixNano())

	c.Set(time.Unix(16000000, 0))

	assert.Equal(t, int64(16000000), c.Now().Unix())

	before := c.Now()

	<-c.After(time.Millisecond * 100)

	assert.Equal(t, before, c.Now())
}