forked from go-bond/bond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
78 lines (53 loc) · 1.56 KB
/
helpers_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package bond
import (
"testing"
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNumberSequence_Next(t *testing.T) {
IDSequence := &NumberSequence{}
id, err := IDSequence.Next()
require.NoError(t, err)
id2, err := IDSequence.Next()
require.NoError(t, err)
require.NotEqual(t, id, id2)
}
func TestNumberSequence_Timestamp(t *testing.T) {
IDSequence := &NumberSequence{}
expectedGreater := time.Now().Unix()
id, err := IDSequence.Next()
require.NoError(t, err)
ts := IDSequence.Timestamp(id)
expectedLess := time.Now().Unix()
assert.GreaterOrEqual(t, ts, uint64(expectedGreater))
assert.LessOrEqual(t, ts, uint64(expectedLess))
}
func TestNumberSequence_SequenceNumber(t *testing.T) {
IDSequence := &NumberSequence{}
id, err := IDSequence.Next()
require.NoError(t, err)
id2, err := IDSequence.Next()
require.NoError(t, err)
ts := IDSequence.SequenceNumber(id)
ts2 := IDSequence.SequenceNumber(id2)
assert.Greater(t, ts2, ts)
assert.Equal(t, ts+1, ts2)
}
func TestNumberSequence_Interface(t *testing.T) {
IDSequence := UniqueKeyGenerator[uint64](&NumberSequence{})
require.NotNil(t, IDSequence)
}
func TestUUIDGenerator_Next(t *testing.T) {
uuidGenerator := &UUIDGenerator{}
id, err := uuidGenerator.Next()
require.NoError(t, err)
id2, err := uuidGenerator.Next()
require.NoError(t, err)
require.NotEqual(t, id, id2)
}
func TestUUIDGenerator_Interface(t *testing.T) {
uuidGenerator := UniqueKeyGenerator[uuid.UUID](&UUIDGenerator{})
require.NotNil(t, uuidGenerator)
}