Skip to content

Commit

Permalink
Remote the un-used workaround used to avoid the lo interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Pignolet <[email protected]>
  • Loading branch information
MatthieuCoder committed Oct 29, 2024
1 parent 006d173 commit 3cb9e40
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"errors"
"fmt"
"net"
"runtime"
"runtime/debug"
Expand Down Expand Up @@ -475,45 +474,13 @@ func TestStatisticsZeroDivision(t *testing.T) {
}
}

func testSetInterfaceNameChooseInterface(t *testing.T) (string, string) {
ifaces, err := net.Interfaces()
AssertNoError(t, err)

for _, i := range ifaces {
name := i.Name
// fix: this is a hack to choose any interface that is not `lo` to a permission issue in CircleCI
if name == "lo" {
continue
}
// find the local address to ping
addrs, err := i.Addrs()
AssertNoError(t, err)

for _, a := range addrs {
switch v := a.(type) {
case *net.IPAddr:
return name, v.IP.String()
case *net.IPNet:
return name, v.IP.String()
}
}
}

// we fail the test if no interface is available
AssertNoError(t, fmt.Errorf("no interface is available for testing"))
return "", ""
}

func TestSetInterfaceName(t *testing.T) {
// we can ping `localhost`, refering to the address in the interface
interfaceName, localAddress := testSetInterfaceNameChooseInterface(t)

pinger := New(localAddress)
pinger := New("localhost")
pinger.Count = 1
pinger.Timeout = time.Second

// Set loopback interface
pinger.InterfaceDevice = interfaceName
pinger.InterfaceDevice = "lo"
err := pinger.Run()
if runtime.GOOS == "linux" {
AssertNoError(t, err)
Expand Down

0 comments on commit 3cb9e40

Please sign in to comment.