mirror of
https://github.com/go-ping/ping.git
synced 2025-06-23 04:37:07 +00:00
feat: add unit test
This commit is contained in:
parent
344d6f322c
commit
25a5dabc81
20
ping_test.go
20
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")
|
||||
|
Loading…
Reference in New Issue
Block a user