go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2101/dhcp_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_dhcp "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/dhcp"
    23  )
    24  
    25  func TestSetInterfaceAsDHCPClient(t *testing.T) {
    26  	ctx, ifHandler := ifTestSetup(t)
    27  	defer ctx.TeardownTestCtx()
    28  
    29  	ctx.MockVpp.MockReply(&vpp_dhcp.DHCPClientConfigReply{})
    30  
    31  	err := ifHandler.SetInterfaceAsDHCPClient(1, "hostName")
    32  
    33  	Expect(err).To(BeNil())
    34  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_dhcp.DHCPClientConfig)
    35  	Expect(ok).To(BeTrue())
    36  	Expect(vppMsg.Client.SwIfIndex).To(BeEquivalentTo(1))
    37  	Expect(vppMsg.Client.Hostname).To(BeEquivalentTo([]byte("hostName")))
    38  	Expect(vppMsg.Client.WantDHCPEvent).To(BeTrue())
    39  	Expect(vppMsg.IsAdd).To(BeTrue())
    40  }
    41  
    42  func TestSetInterfaceAsDHCPClientError(t *testing.T) {
    43  	ctx, ifHandler := ifTestSetup(t)
    44  	defer ctx.TeardownTestCtx()
    45  
    46  	ctx.MockVpp.MockReply(&vpp_dhcp.DHCPComplEvent{})
    47  
    48  	err := ifHandler.SetInterfaceAsDHCPClient(1, "hostName")
    49  
    50  	Expect(err).ToNot(BeNil())
    51  }
    52  
    53  func TestSetInterfaceAsDHCPClientRetval(t *testing.T) {
    54  	ctx, ifHandler := ifTestSetup(t)
    55  	defer ctx.TeardownTestCtx()
    56  
    57  	ctx.MockVpp.MockReply(&vpp_dhcp.DHCPClientConfigReply{
    58  		Retval: 1,
    59  	})
    60  
    61  	err := ifHandler.SetInterfaceAsDHCPClient(1, "hostName")
    62  
    63  	Expect(err).ToNot(BeNil())
    64  }
    65  
    66  func TestUnsetInterfaceAsDHCPClient(t *testing.T) {
    67  	ctx, ifHandler := ifTestSetup(t)
    68  	defer ctx.TeardownTestCtx()
    69  
    70  	ctx.MockVpp.MockReply(&vpp_dhcp.DHCPClientConfigReply{})
    71  
    72  	err := ifHandler.UnsetInterfaceAsDHCPClient(1, "hostName")
    73  
    74  	Expect(err).To(BeNil())
    75  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_dhcp.DHCPClientConfig)
    76  	Expect(ok).To(BeTrue())
    77  	Expect(vppMsg.Client.SwIfIndex).To(BeEquivalentTo(1))
    78  	Expect(vppMsg.Client.Hostname).To(BeEquivalentTo([]byte("hostName")))
    79  	Expect(vppMsg.Client.WantDHCPEvent).To(BeTrue())
    80  	Expect(vppMsg.IsAdd).To(BeFalse())
    81  }
    82  
    83  func TestUnsetInterfaceAsDHCPClientError(t *testing.T) {
    84  	ctx, ifHandler := ifTestSetup(t)
    85  	defer ctx.TeardownTestCtx()
    86  
    87  	ctx.MockVpp.MockReply(&vpp_dhcp.DHCPComplEvent{})
    88  
    89  	err := ifHandler.UnsetInterfaceAsDHCPClient(1, "hostName")
    90  
    91  	Expect(err).ToNot(BeNil())
    92  }
    93  
    94  func TestUnsetInterfaceAsDHCPClientRetval(t *testing.T) {
    95  	ctx, ifHandler := ifTestSetup(t)
    96  	defer ctx.TeardownTestCtx()
    97  
    98  	ctx.MockVpp.MockReply(&vpp_dhcp.DHCPClientConfigReply{
    99  		Retval: 1,
   100  	})
   101  
   102  	err := ifHandler.UnsetInterfaceAsDHCPClient(1, "hostName")
   103  
   104  	Expect(err).ToNot(BeNil())
   105  }