forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathid_test.go
51 lines (47 loc) · 1.04 KB
/
id_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
package rand
import (
"encoding/binary"
"reflect"
"testing"
"github.com/influxdata/influxdb/v2/kit/platform"
)
func TestOrgBucketID_ID(t *testing.T) {
tests := []struct {
name string
seed int64
want platform.ID
}{
{
name: "when seeded with 6 the first random number contains characters",
seed: 6,
want: platform.ID(0xaddff35d7fe88f15),
},
{
name: "when seeded with 1234567890 we get a random number without any bad chars",
seed: 1234567890,
want: platform.ID(0x8a95c1bf40518fee),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := NewOrgBucketID(tt.seed)
if got := r.ID(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("OrgBucketID.ID() = %v, want %v", got, tt.want)
}
})
}
}
func TestOrgBucketID_ID_sanitized(t *testing.T) {
r := NewOrgBucketID(42)
b := make([]byte, 8)
for i := 0; i < 1000; i++ {
id := r.ID()
binary.LittleEndian.PutUint64(b, uint64(id))
for j := range b {
switch b[j] {
case 0x5C, 0x2C, 0x20:
t.Fatalf("unexpected bytes found in IDs")
}
}
}
}