github.com/osrg/gobgp@v2.0.0+incompatible/cmd/gobgp/common_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/stretchr/testify/assert"
    23  )
    24  
    25  func Test_ExtractReserved(t *testing.T) {
    26  	assert := assert.New(t)
    27  	args := strings.Split("10 rt 100:100 med 10 nexthop 10.0.0.1 aigp metric 10 local-pref 100", " ")
    28  	keys := map[string]int{
    29  		"rt":         paramList,
    30  		"med":        paramSingle,
    31  		"nexthop":    paramSingle,
    32  		"aigp":       paramList,
    33  		"local-pref": paramSingle}
    34  	m, _ := extractReserved(args, keys)
    35  	assert.True(len(m["rt"]) == 1)
    36  	assert.True(len(m["med"]) == 1)
    37  	assert.True(len(m["nexthop"]) == 1)
    38  	assert.True(len(m["aigp"]) == 2)
    39  	assert.True(len(m["local-pref"]) == 1)
    40  }