-
Notifications
You must be signed in to change notification settings - Fork 0
/
snowflake_test.go
42 lines (33 loc) · 862 Bytes
/
snowflake_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
package gotils_test
import (
"fmt"
"log"
"testing"
"time"
"github.com/korovkin/gotils"
. "github.com/onsi/gomega"
)
func init() {
log.SetFlags(log.Ltime | log.Lshortfile | log.Lmicroseconds | log.Ldate)
}
func TestSnowflake(t *testing.T) {
RegisterTestingT(t)
t.Run("snowflake", func(_ *testing.T) {
now := time.Now()
const idType = "BATMAN"
a := gotils.SnowflakeID(idType, now)
b := gotils.SnowflakeID(idType, now)
log.Println("a:", a)
log.Println("b:", b)
Expect(a).NotTo(BeEquivalentTo(b))
cGroup, c := gotils.SnowflakeIDWithGroup(idType, now)
Expect(c).To(HavePrefix(idType))
aGroup := gotils.SnowflakeExtractGroup(a, idType)
group := fmt.Sprintf("%04d%02d%02d",
now.UTC().Year(),
now.UTC().Month(),
now.UTC().Day())
Expect(aGroup).To(BeEquivalentTo(group))
Expect(cGroup).To(BeEquivalentTo(group))
})
}