Skip to content

Commit

Permalink
Fix integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Aug 18, 2021
1 parent 0a2a761 commit a5ac3ec
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/integration/agent/ip_assigner_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,25 @@ import (
const dummyDeviceName = "antrea-dummy0"

func TestIPAssigner(t *testing.T) {
ipAssigner, err := ipassigner.NewIPAssigner(net.ParseIP("127.0.0.1"), dummyDeviceName)
var nodeIP net.IP
linkList, err := net.Interfaces()
require.NoError(t, err)
for _, link := range linkList {
if link.HardwareAddr == nil {
continue
}
addrList, err := link.Addrs()
if err != nil {
continue
}
for _, addr := range addrList {
if ipNet, ok := addr.(*net.IPNet); ok {
nodeIP = ipNet.IP
break
}
}
}
ipAssigner, err := ipassigner.NewIPAssigner(nodeIP, dummyDeviceName)
require.NoError(t, err, "Initializing IP assigner failed")

dummyDevice, err := netlink.LinkByName(dummyDeviceName)
Expand All @@ -43,7 +61,7 @@ func TestIPAssigner(t *testing.T) {

ip1 := "10.10.10.10"
ip2 := "10.10.10.11"
ip3 := "2621:124:6020:1006:250:56ff:fea7:36c2"
ip3 := "2021:124:6020:1006:250:56ff:fea7:36c2"
desiredIPs := sets.NewString(ip1, ip2, ip3)

for ip := range desiredIPs {
Expand All @@ -63,7 +81,7 @@ func TestIPAssigner(t *testing.T) {
assert.Equal(t, desiredIPs, actualIPs, "Actual IPs don't match")

// NewIPAssigner should load existing IPs correctly.
newIPAssigner, err := ipassigner.NewIPAssigner(net.ParseIP("127.0.0.1"), dummyDeviceName)
newIPAssigner, err := ipassigner.NewIPAssigner(nodeIP, dummyDeviceName)
require.NoError(t, err, "Initializing new IP assigner failed")
assert.Equal(t, desiredIPs, newIPAssigner.AssignedIPs(), "Assigned IPs don't match")

Expand Down

0 comments on commit a5ac3ec

Please sign in to comment.