github.com/imran-kn/cilium-fork@v1.6.9/pkg/envoy/xds/node_test.go (about)

     1  // Copyright 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 xds
    18  
    19  import (
    20  	envoy_api_v2_core "github.com/cilium/proxy/go/envoy/api/v2/core"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  type NodeSuite struct{}
    26  
    27  var _ = Suite(&NodeSuite{})
    28  
    29  func (s *NodeSuite) TestIstioNodeToIP(c *C) {
    30  	var node envoy_api_v2_core.Node
    31  	var ip string
    32  	var err error
    33  
    34  	node.Id = "sidecar~10.1.1.0~v0.default~default.svc.cluster.local"
    35  	ip, err = IstioNodeToIP(&node)
    36  	c.Assert(err, IsNil)
    37  	c.Check(ip, Equals, "10.1.1.0")
    38  
    39  	node.Id = "sidecar~10.1.1.0~v0.default"
    40  	_, err = IstioNodeToIP(&node)
    41  	c.Assert(err, Not(IsNil))
    42  
    43  	node.Id = "sidecar~not-an-ip~v0.default~default.svc.cluster.local"
    44  	_, err = IstioNodeToIP(&node)
    45  	c.Assert(err, Not(IsNil))
    46  }