-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsnowflake_test.go
71 lines (58 loc) · 1.49 KB
/
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
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
package tempest
import (
"testing"
)
func TestUserSnowflake(t *testing.T) {
const RawSnowflake = "327690719085068289"
t.Run("success", func(t *testing.T) {
s, err := StringToSnowflake(RawSnowflake)
if err != nil {
t.Error(err)
}
if s.CreationTimestamp().UnixMilli() != 1498197955629 {
t.Errorf("failed to read creation timestamp from %s snowflake", s.String())
}
})
t.Run("failure/creation", func(t *testing.T) {
_, err := StringToSnowflake(RawSnowflake + "a")
if err == nil {
t.Error(err)
}
})
}
func TestChannelSnowflake(t *testing.T) {
const RawSnowflake = "1055582516565782599"
t.Run("success", func(t *testing.T) {
s, err := StringToSnowflake(RawSnowflake)
if err != nil {
t.Error(err)
}
if s.CreationTimestamp().UnixMilli() != 1671740883724 {
t.Errorf("failed to read creation timestamp from %s snowflake", s.String())
}
})
t.Run("failure/creation", func(t *testing.T) {
_, err := StringToSnowflake(RawSnowflake + "a")
if err == nil {
t.Error(err)
}
})
}
func TestGuildSnowflake(t *testing.T) {
const RawSnowflake = "613425648685547541"
t.Run("success", func(t *testing.T) {
s, err := StringToSnowflake(RawSnowflake)
if err != nil {
t.Error(err)
}
if s.CreationTimestamp().UnixMilli() != 1566322471544 {
t.Errorf("failed to read creation timestamp from %s snowflake", s.String())
}
})
t.Run("failure/creation", func(t *testing.T) {
_, err := StringToSnowflake(RawSnowflake + "a")
if err == nil {
t.Error(err)
}
})
}