1
// Copyright 2022 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
21
"github.com/stretchr/testify/require"
24
func TestVuid(t *testing.T) {
25
_, err := NewVuid(1, 1, 0)
28
vid := Vid(rand.Uint32())
29
index := uint8(rand.Intn(256))
30
epoch := uint32(rand.Int31n(MaxEpoch-MinEpoch) + MinEpoch)
31
vuid, err := NewVuid(vid, index, epoch)
32
vuidPre := EncodeVuidPrefix(vid, index)
33
require.NoError(t, err)
34
require.True(t, vuid.IsValid())
36
require.Equal(t, vuidPre, vuid.VuidPrefix())
37
require.Equal(t, vid, vuidPre.Vid())
38
require.Equal(t, index, vuidPre.Index())
39
require.Equal(t, vid, vuid.Vid())
40
require.Equal(t, index, vuid.Index())
41
require.Equal(t, epoch, vuid.Epoch())
44
func TestVuidMulti(t *testing.T) {
45
for range [1000]struct{}{} {
50
func TestDecodeVuid(t *testing.T) {
51
for _, vuid := range []Vuid{425335980033, 116131889167} {
52
t.Log(vuid.Vid(), vuid.VuidPrefix(), vuid.Index(), vuid.Epoch(), vuid.ToString())
53
require.Equal(t, vuid, EncodeVuid(vuid.VuidPrefix(), vuid.Epoch()))