Skip to content
Permalink
Browse files

add udp reachable check (#545)

* add udp reachable check

add integration test for udp

* refactor for how variable creating
  • Loading branch information
weakiwi committed Feb 17, 2020
1 parent 09b559d commit 81d5f150797ed49fd9389acd2fb53070a7813fd2
@@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: false
@@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: false
@@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
@@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
@@ -24,6 +24,8 @@ goss a "${args[@]}" package $package foobar vim-tiny

goss a "${args[@]}" addr --timeout 1s google.com:443 google.com:22

goss a "${args[@]}" addr --timeout 1s udp://8.8.8.8:53

goss a "${args[@]}" port tcp:80 tcp6:80 9999

goss a "${args[@]}" service $package foobar
@@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
@@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
@@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
@@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
@@ -40,10 +40,12 @@ func (a *DefAddr) Exists() (bool, error) { return a.Reachable() }
func (a *DefAddr) Reachable() (bool, error) {
network, address := splitAddress(a.address)

localAddr := &net.TCPAddr{
IP: net.ParseIP(a.LocalAddress),
var localAddr net.Addr
if network == "udp" {
localAddr = &net.UDPAddr{IP: net.ParseIP(a.LocalAddress)}
} else {
localAddr = &net.TCPAddr{IP: net.ParseIP(a.LocalAddress)}
}

d := net.Dialer{LocalAddr: localAddr, Timeout: time.Duration(a.Timeout) * time.Millisecond}
conn, err := d.Dial(network, address)
if err != nil {

0 comments on commit 81d5f15

Please sign in to comment.
You can’t perform that action at this time.