go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2101/subif_vppcalls_test.go (about)

     1  // Copyright (c) 2019 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 vpp2101_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/vpp2101/interface"
    23  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/interface_types"
    24  )
    25  
    26  func TestCreateSubif(t *testing.T) {
    27  	ctx, ifHandler := ifTestSetup(t)
    28  	defer ctx.TeardownTestCtx()
    29  	ctx.MockVpp.MockReply(&vpp_ifs.CreateVlanSubifReply{
    30  		SwIfIndex: 2,
    31  	})
    32  	swifindex, err := ifHandler.CreateSubif(5, 32)
    33  	Expect(err).To(BeNil())
    34  	Expect(swifindex).To(Equal(uint32(2)))
    35  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.CreateVlanSubif)
    36  	Expect(ok).To(BeTrue())
    37  	Expect(vppMsg).ToNot(BeNil())
    38  	Expect(vppMsg.SwIfIndex).To(Equal(interface_types.InterfaceIndex(5)))
    39  	Expect(vppMsg.VlanID).To(Equal(uint32(32)))
    40  }
    41  
    42  func TestCreateSubifError(t *testing.T) {
    43  	ctx, ifHandler := ifTestSetup(t)
    44  	defer ctx.TeardownTestCtx()
    45  	ctx.MockVpp.MockReply(&vpp_ifs.CreateVlanSubifReply{
    46  		SwIfIndex: 2,
    47  		Retval:    9,
    48  	})
    49  	swifindex, err := ifHandler.CreateSubif(5, 32)
    50  	Expect(err).ToNot(BeNil())
    51  	Expect(swifindex).To(Equal(uint32(0)))
    52  }
    53  
    54  func TestDeleteSubif(t *testing.T) {
    55  	ctx, ifHandler := ifTestSetup(t)
    56  	defer ctx.TeardownTestCtx()
    57  	ctx.MockVpp.MockReply(&vpp_ifs.DeleteSubifReply{
    58  		Retval: 2,
    59  	})
    60  	err := ifHandler.DeleteSubif(5)
    61  	Expect(err).ToNot(BeNil())
    62  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.DeleteSubif)
    63  	Expect(ok).To(BeTrue())
    64  	Expect(vppMsg).ToNot(BeNil())
    65  	Expect(vppMsg.SwIfIndex).To(Equal(interface_types.InterfaceIndex(5)))
    66  }
    67  
    68  func TestDeleteSubifError(t *testing.T) {
    69  	ctx, ifHandler := ifTestSetup(t)
    70  	defer ctx.TeardownTestCtx()
    71  	ctx.MockVpp.MockReply(&vpp_ifs.DeleteSubifReply{
    72  		Retval: 2,
    73  	})
    74  	err := ifHandler.DeleteSubif(5)
    75  	Expect(err).ToNot(BeNil())
    76  }