github.com/osrg/gobgp@v2.0.0+incompatible/cmd/gobgp/global_test.go (about)

     1  // Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
     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
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package main
    17  
    18  import (
    19  	"strings"
    20  	"testing"
    21  
    22  	"github.com/osrg/gobgp/internal/pkg/apiutil"
    23  	"github.com/osrg/gobgp/pkg/packet/bgp"
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func Test_ParsePath(t *testing.T) {
    28  	assert := assert.New(t)
    29  	buf := "10.0.0.0/24 rt 100:100 med 10 nexthop 10.0.0.1 aigp metric 10 local-pref 100"
    30  
    31  	path, err := parsePath(bgp.RF_IPv4_UC, strings.Split(buf, " "))
    32  	assert.Nil(err)
    33  	i := 0
    34  	attrs, _ := apiutil.GetNativePathAttributes(path)
    35  	for _, a := range attrs {
    36  		assert.True(i < int(a.GetType()))
    37  		i = int(a.GetType())
    38  	}
    39  }