mirror of
https://github.com/go-ping/ping.git
synced 2025-06-24 05:07: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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"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
|
// Test helpers
|
||||||
func makeTestPinger() *Pinger {
|
func makeTestPinger() *Pinger {
|
||||||
pinger := New("127.0.0.1")
|
pinger := New("127.0.0.1")
|
||||||
|
Loading…
Reference in New Issue
Block a user