diff --git a/ping_test.go b/ping_test.go index aa0c166..2a99b3b 100644 --- a/ping_test.go +++ b/ping_test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net" + "runtime" "runtime/debug" "sync/atomic" "testing" @@ -476,6 +477,25 @@ func TestStatisticsLossy(t *testing.T) { } } +func TestSetIfaceName(t *testing.T) { + pinger := New("www.google.com") + pinger.Count = 1 + + // Set loopback interface + pinger.Iface = "lo" + err := pinger.Run() + if runtime.GOOS == "linux" { + AssertNoError(t, err) + } else { + AssertError(t, err, "other platforms unsupport this feature") + } + + // Set fake interface + pinger.Iface = "L()0pB@cK" + err = pinger.Run() + AssertError(t, err, "device not found") +} + // Test helpers func makeTestPinger() *Pinger { pinger := New("127.0.0.1")