Add ability to set outgouing interface (only Linux support). Fix test

This commit is contained in:
TimofeyAf 2022-02-23 14:28:42 +03:00
parent 72dfce2120
commit 47c097f8b4
2 changed files with 9 additions and 4 deletions

View File

@ -24,7 +24,7 @@ style:
.PHONY: test
test:
@echo ">> running all tests"
GO111MODULE=$(GO111MODULE) $(GO) test -race -cover $(GOOPTS) $(pkgs)
GO111MODULE=$(GO111MODULE) $(GO) test -race -cover -short $(GOOPTS) $(pkgs)
.PHONY: vet
vet:

View File

@ -387,21 +387,26 @@ func TestSetIPAddr(t *testing.T) {
}
func TestBindToDevice(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
// Create a localhost ipv4 pinger
pinger := New("127.0.0.1")
pinger.ipv4 = true
pinger.Count = 1
// Set loopback interface: "lo"
// Set loopback interface
pinger.Iface = "lo"
err := pinger.Run()
if runtime.GOOS == "linux" {
AssertNoError(t, err)
} else {
AssertError(t, err, "other platforms unsupported this feature")
AssertError(t, err, "other platforms unsupport this feature")
}
// Set fake interface: "L()0pB@cK"
// Set fake interface
pinger.Iface = "L()0pB@cK"
err = pinger.Run()
AssertError(t, err, "device not found")