forked from darccio/go-ulid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathulid_test.go
59 lines (53 loc) · 1.06 KB
/
ulid_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
package ulid
import (
"testing"
"time"
)
func TestSetTime(t *testing.T) {
var (
ulid ULID
ts = time.Unix(1469918176, 385000000)
)
tm := ts.UnixNano() / int64(time.Millisecond)
if tm != 1469918176385 {
t.Fatalf("expected 1469918176385, got '%v'", tm)
}
setTime(&ulid, ts)
et := ulid.String()
if et[:10] != "01ARYZ6S41" {
t.Fatalf("expected '01ARYZ6S41', got '%s'", et[:10])
}
}
func TestSetTimeAfterSetRandom(t *testing.T) {
var (
ulid ULID
ts = time.Unix(1469918176, 385000000)
)
tm := ts.UnixNano() / int64(time.Millisecond)
if tm != 1469918176385 {
t.Fatalf("expected 1469918176385, got '%v'", tm)
}
setRandom(&ulid)
setTime(&ulid, ts)
et := ulid.String()
if et[:10] != "01ARYZ6S41" {
t.Fatalf("expected '01ARYZ6S41', got '%s'", et[:10])
}
}
func BenchmarkULID(b *testing.B) {
for i := 0; i < b.N; i++ {
New()
}
}
func BenchmarkEncodedULID(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = New().String()
}
}
func BenchmarkSingleEncodedULID(b *testing.B) {
u := New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = u.String()
}
}