go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2106/loopback_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 TestAddLoopbackInterface(t *testing.T) { 26 ctx, ifHandler := ifTestSetup(t) 27 defer ctx.TeardownTestCtx() 28 29 ctx.MockVpp.MockReply(&vpp_ifs.CreateLoopbackReply{ 30 SwIfIndex: 1, 31 }) 32 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{}) 33 34 swIfIdx, err := ifHandler.AddLoopbackInterface("loopback") 35 36 Expect(err).To(BeNil()) 37 Expect(swIfIdx).To(BeEquivalentTo(1)) 38 } 39 40 func TestAddLoopbackInterfaceError(t *testing.T) { 41 ctx, ifHandler := ifTestSetup(t) 42 defer ctx.TeardownTestCtx() 43 44 ctx.MockVpp.MockReply(&vpp_ifs.CreateLoopback{}) 45 46 swIfIdx, err := ifHandler.AddLoopbackInterface("loopback") 47 48 Expect(err).ToNot(BeNil()) 49 Expect(swIfIdx).To(BeEquivalentTo(0)) 50 } 51 52 func TestAddLoopbackInterfaceRetval(t *testing.T) { 53 ctx, ifHandler := ifTestSetup(t) 54 defer ctx.TeardownTestCtx() 55 56 ctx.MockVpp.MockReply(&vpp_ifs.CreateLoopbackReply{ 57 Retval: 1, 58 }) 59 60 swIfIdx, err := ifHandler.AddLoopbackInterface("loopback") 61 62 Expect(err).ToNot(BeNil()) 63 Expect(swIfIdx).To(BeEquivalentTo(0)) 64 } 65 66 func TestDeleteLoopbackInterface(t *testing.T) { 67 ctx, ifHandler := ifTestSetup(t) 68 defer ctx.TeardownTestCtx() 69 70 ctx.MockVpp.MockReply(&vpp_ifs.DeleteLoopbackReply{}) 71 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{}) 72 73 err := ifHandler.DeleteLoopbackInterface("loopback", 1) 74 75 Expect(err).To(BeNil()) 76 } 77 78 func TestDeleteLoopbackInterfaceError(t *testing.T) { 79 ctx, ifHandler := ifTestSetup(t) 80 defer ctx.TeardownTestCtx() 81 82 ctx.MockVpp.MockReply(&vpp_ifs.DeleteLoopback{}) 83 84 err := ifHandler.DeleteLoopbackInterface("loopback", 1) 85 86 Expect(err).ToNot(BeNil()) 87 } 88 89 func TestDeleteLoopbackInterfaceRetval(t *testing.T) { 90 ctx, ifHandler := ifTestSetup(t) 91 defer ctx.TeardownTestCtx() 92 93 ctx.MockVpp.MockReply(&vpp_ifs.DeleteLoopbackReply{ 94 Retval: 1, 95 }) 96 97 err := ifHandler.DeleteLoopbackInterface("loopback", 1) 98 99 Expect(err).ToNot(BeNil()) 100 }