go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2106/vrf_vppcalls_test.go (about) 1 // Copyright (c) 2021 Cisco and/or its affiliates. 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 package vpp2106_test 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 22 vpp_ifs "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/interface" 23 ) 24 25 func TestGetInterfaceVRF(t *testing.T) { 26 ctx, ifHandler := ifTestSetup(t) 27 defer ctx.TeardownTestCtx() 28 29 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceGetTableReply{ 30 VrfID: 1, 31 }) 32 33 vrfID, err := ifHandler.GetInterfaceVrf(1) 34 Expect(err).To(BeNil()) 35 Expect(vrfID).To(BeEquivalentTo(1)) 36 } 37 38 func TestGetInterfaceIPv6VRF(t *testing.T) { 39 ctx, ifHandler := ifTestSetup(t) 40 defer ctx.TeardownTestCtx() 41 42 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceGetTableReply{ 43 VrfID: 1, 44 }) 45 46 vrfID, err := ifHandler.GetInterfaceVrfIPv6(1) 47 Expect(err).To(BeNil()) 48 Expect(vrfID).To(BeEquivalentTo(1)) 49 } 50 51 func TestGetInterfaceVRFError(t *testing.T) { 52 ctx, ifHandler := ifTestSetup(t) 53 defer ctx.TeardownTestCtx() 54 55 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceGetTable{}) 56 57 _, err := ifHandler.GetInterfaceVrf(1) 58 Expect(err).ToNot(BeNil()) 59 } 60 61 func TestGetInterfaceVRFRetval(t *testing.T) { 62 ctx, ifHandler := ifTestSetup(t) 63 defer ctx.TeardownTestCtx() 64 65 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceGetTableReply{ 66 Retval: 1, 67 }) 68 69 _, err := ifHandler.GetInterfaceVrf(1) 70 Expect(err).ToNot(BeNil()) 71 } 72 73 func TestSetInterfaceVRF(t *testing.T) { 74 ctx, ifHandler := ifTestSetup(t) 75 defer ctx.TeardownTestCtx() 76 77 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetTableReply{}) 78 79 err := ifHandler.SetInterfaceVrf(1, 2) 80 Expect(err).To(BeNil()) 81 vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetTable) 82 Expect(ok).To(BeTrue()) 83 Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1)) 84 Expect(vppMsg.VrfID).To(BeEquivalentTo(2)) 85 } 86 87 func TestSetInterfaceIPv6VRF(t *testing.T) { 88 ctx, ifHandler := ifTestSetup(t) 89 defer ctx.TeardownTestCtx() 90 91 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetTableReply{}) 92 93 err := ifHandler.SetInterfaceVrfIPv6(1, 2) 94 Expect(err).To(BeNil()) 95 vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetTable) 96 Expect(ok).To(BeTrue()) 97 Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1)) 98 Expect(vppMsg.VrfID).To(BeEquivalentTo(2)) 99 Expect(vppMsg.IsIPv6).To(BeTrue()) 100 } 101 102 func TestSetInterfaceVRFError(t *testing.T) { 103 ctx, ifHandler := ifTestSetup(t) 104 defer ctx.TeardownTestCtx() 105 106 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetTable{}) 107 108 err := ifHandler.SetInterfaceVrf(1, 2) 109 Expect(err).To(HaveOccurred()) 110 } 111 112 func TestSetInterfaceVRFRetval(t *testing.T) { 113 ctx, ifHandler := ifTestSetup(t) 114 defer ctx.TeardownTestCtx() 115 116 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetTableReply{ 117 Retval: 1, 118 }) 119 120 err := ifHandler.SetInterfaceVrf(1, 2) 121 Expect(err).ToNot(BeNil()) 122 }