github.com/osrg/gobgp/v3@v3.30.0/pkg/config/oc/util_test.go (about) 1 // Copyright (C) 2017 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 oc 17 18 import ( 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 ) 23 24 func TestDetectConfigFileType(t *testing.T) { 25 assert := assert.New(t) 26 27 assert.Equal("toml", detectConfigFileType("bgpd.conf", "toml")) 28 assert.Equal("toml", detectConfigFileType("bgpd.toml", "xxx")) 29 assert.Equal("yaml", detectConfigFileType("bgpd.yaml", "xxx")) 30 assert.Equal("yaml", detectConfigFileType("bgpd.yml", "xxx")) 31 assert.Equal("json", detectConfigFileType("bgpd.json", "xxx")) 32 } 33 34 func TestIsAfiSafiChanged(t *testing.T) { 35 v4 := AfiSafi{ 36 Config: AfiSafiConfig{ 37 AfiSafiName: AFI_SAFI_TYPE_IPV4_UNICAST, 38 }, 39 } 40 v6 := AfiSafi{ 41 Config: AfiSafiConfig{ 42 AfiSafiName: AFI_SAFI_TYPE_IPV6_UNICAST, 43 }, 44 } 45 old := []AfiSafi{v4} 46 new := []AfiSafi{v4} 47 assert.False(t, isAfiSafiChanged(old, new)) 48 49 new = append(new, v6) 50 assert.True(t, isAfiSafiChanged(old, new)) 51 52 new = []AfiSafi{v6} 53 assert.True(t, isAfiSafiChanged(old, new)) 54 v4ap := v4 55 v4ap.AddPaths.Config.Receive = true 56 new = []AfiSafi{v4ap} 57 assert.True(t, isAfiSafiChanged(old, new)) 58 }