feat: add unit test

This commit is contained in:
ilolicon 2023-04-11 18:51:04 +08:00
parent 344d6f322c
commit 25a5dabc81

View File

@ -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")