From 83e9565dc61e987848256b72ec576ce682ad30c0 Mon Sep 17 00:00:00 2001 From: Prince Pereira Date: Tue, 7 Feb 2023 16:04:41 +0530 Subject: [PATCH] [#115501] Unit testcase for the fix for issue with missing Loadbalancer policies for IPV6 endpoints in Dualstack mode. --- pkg/proxy/winkernel/hns_test.go | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pkg/proxy/winkernel/hns_test.go b/pkg/proxy/winkernel/hns_test.go index fe3ce751ccb..66fb19e0b4d 100644 --- a/pkg/proxy/winkernel/hns_test.go +++ b/pkg/proxy/winkernel/hns_test.go @@ -23,6 +23,7 @@ import ( "encoding/json" "github.com/Microsoft/hcsshim/hcn" + "github.com/stretchr/testify/assert" "strings" "testing" @@ -37,6 +38,7 @@ const ( gatewayAddress = "192.168.1.1" epMacAddress = "00-11-22-33-44-55" epIpAddress = "192.168.1.3" + epIpv6Address = "192::3" epIpAddressB = "192.168.1.4" epIpAddressRemote = "192.168.2.3" epPaAddress = "10.0.0.3" @@ -63,6 +65,51 @@ func TestGetNetworkByName(t *testing.T) { } } +func TestGetAllEndpointsByNetwork(t *testing.T) { + hns := hns{} + Network := mustTestNetwork(t) + + ipv4Config := &hcn.IpConfig{ + IpAddress: epIpAddress, + } + ipv6Config := &hcn.IpConfig{ + IpAddress: epIpv6Address, + } + Endpoint := &hcn.HostComputeEndpoint{ + IpConfigurations: []hcn.IpConfig{*ipv4Config, *ipv6Config}, + MacAddress: epMacAddress, + SchemaVersion: hcn.SchemaVersion{ + Major: 2, + Minor: 0, + }, + } + Endpoint, err := Network.CreateEndpoint(Endpoint) + if err != nil { + t.Error(err) + } + + mapEndpointsInfo, err := hns.getAllEndpointsByNetwork(Network.Name) + if err != nil { + t.Error(err) + } + endpointIpv4, ipv4EpPresent := mapEndpointsInfo[ipv4Config.IpAddress] + assert.True(t, ipv4EpPresent, "IPV4 endpoint is missing in Dualstack mode") + assert.Equal(t, endpointIpv4.ip, epIpAddress, "IPV4 IP is missing in Dualstack mode") + + endpointIpv6, ipv6EpPresent := mapEndpointsInfo[ipv6Config.IpAddress] + assert.True(t, ipv6EpPresent, "IPV6 endpoint is missing in Dualstack mode") + assert.Equal(t, endpointIpv6.ip, epIpv6Address, "IPV6 IP is missing in Dualstack mode") + + err = Endpoint.Delete() + if err != nil { + t.Error(err) + } + err = Network.Delete() + if err != nil { + t.Error(err) + } +} + func TestGetEndpointByID(t *testing.T) { hns := hns{} Network := mustTestNetwork(t)