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.
20
"github.com/stretchr/testify/require"
22
"github.com/cubefs/cubefs/blobstore/common/proto"
25
func TestProtoDiskID(t *testing.T) {
27
bytes := []byte{0x00, 0x00, 0x00, 0x09}
28
require.Equal(t, uint32(9), uint32(id))
29
require.Equal(t, bytes, id.Encode())
30
require.Equal(t, "9", id.ToString())
33
require.Equal(t, id, dec.Decode(bytes))
34
require.Equal(t, id, dec)
37
func TestProtoVID(t *testing.T) {
39
require.Equal(t, "123", id.ToString())
42
func TestProtoClusterID(t *testing.T) {
43
id := proto.ClusterID(10)
44
require.Equal(t, "10", id.ToString())
47
func TestProtoToken(t *testing.T) {
48
host := "127.0.0.1:80"
50
token := "127.0.0.1:80;123"
51
require.Equal(t, token, proto.EncodeToken(host, vid))
53
newHost, newVid, err := proto.DecodeToken(token)
54
require.NoError(t, err)
55
require.Equal(t, host, newHost)
56
require.Equal(t, vid, newVid)
59
_, _, err := proto.DecodeToken(host)
63
_, _, err := proto.DecodeToken(token + ";")