github.phpd.cn/cilium/cilium@v1.6.12/pkg/identity/numericidentity_test.go (about)

     1  // Copyright 2016-2018 Authors of Cilium
     2  //
     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
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     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 implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build !privileged_tests
    16  
    17  package identity
    18  
    19  import (
    20  	"github.com/cilium/cilium/pkg/option"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  func (s *IdentityTestSuite) TestLocalIdentity(c *C) {
    26  	localID := NumericIdentity(LocalIdentityFlag | 1)
    27  	c.Assert(localID.HasLocalScope(), Equals, true)
    28  
    29  	maxClusterID := NumericIdentity(option.ClusterIDMax | 1)
    30  	c.Assert(maxClusterID.HasLocalScope(), Equals, false)
    31  
    32  	c.Assert(ReservedIdentityWorld.HasLocalScope(), Equals, false)
    33  }
    34  
    35  func (s *IdentityTestSuite) TestClusterID(c *C) {
    36  	tbl := []struct {
    37  		identity  uint32
    38  		clusterID int
    39  	}{
    40  		{
    41  			identity:  0x000000,
    42  			clusterID: 0,
    43  		},
    44  		{
    45  			identity:  0x010000,
    46  			clusterID: 1,
    47  		},
    48  		{
    49  			identity:  0x2A0000,
    50  			clusterID: 42,
    51  		},
    52  		{
    53  			identity:  0xFF0000,
    54  			clusterID: 255,
    55  		},
    56  		{ // make sure we support min/max configuration values
    57  			identity:  option.ClusterIDMin << 16,
    58  			clusterID: option.ClusterIDMin,
    59  		},
    60  		{
    61  			identity:  option.ClusterIDMax << 16,
    62  			clusterID: option.ClusterIDMax,
    63  		},
    64  	}
    65  
    66  	for _, item := range tbl {
    67  		c.Assert(NumericIdentity(item.identity).ClusterID(), Equals, item.clusterID)
    68  	}
    69  }