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

     1  //  Copyright (c) 2022 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 vpp2210_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/vpp2210/interface"
    23  	vpp2210 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/vppcalls/vpp2210"
    24  )
    25  
    26  func TestSetInterfaceMac(t *testing.T) {
    27  	ctx, ifHandler := ifTestSetup(t)
    28  	defer ctx.TeardownTestCtx()
    29  
    30  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetMacAddressReply{})
    31  
    32  	mac, err := vpp2210.ParseMAC("65:77:BF:72:C9:8D")
    33  	Expect(err).To(BeNil())
    34  	err = ifHandler.SetInterfaceMac(1, "65:77:BF:72:C9:8D")
    35  	Expect(err).To(BeNil())
    36  
    37  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetMacAddress)
    38  	Expect(ok).To(BeTrue())
    39  	Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1))
    40  	Expect(vppMsg.MacAddress).To(BeEquivalentTo(mac))
    41  }
    42  
    43  func TestSetInterfaceInvalidMac(t *testing.T) {
    44  	ctx, ifHandler := ifTestSetup(t)
    45  	defer ctx.TeardownTestCtx()
    46  
    47  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetMacAddress{})
    48  
    49  	err := ifHandler.SetInterfaceMac(1, "invalid-mac")
    50  
    51  	Expect(err).ToNot(BeNil())
    52  }
    53  
    54  func TestSetInterfaceMacError(t *testing.T) {
    55  	ctx, ifHandler := ifTestSetup(t)
    56  	defer ctx.TeardownTestCtx()
    57  
    58  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetMacAddress{})
    59  
    60  	err := ifHandler.SetInterfaceMac(1, "65:77:BF:72:C9:8D")
    61  
    62  	Expect(err).ToNot(BeNil())
    63  }
    64  
    65  func TestSetInterfaceMacRetval(t *testing.T) {
    66  	ctx, ifHandler := ifTestSetup(t)
    67  	defer ctx.TeardownTestCtx()
    68  
    69  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetMacAddressReply{
    70  		Retval: 1,
    71  	})
    72  
    73  	err := ifHandler.SetInterfaceMac(1, "65:77:BF:72:C9:8D")
    74  
    75  	Expect(err).ToNot(BeNil())
    76  }