summaryrefslogtreecommitdiff
path: root/libgo/go/net/udp_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/udp_test.go')
-rw-r--r--libgo/go/net/udp_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/libgo/go/net/udp_test.go b/libgo/go/net/udp_test.go
index f80d3b5a9cf..37b904f3242 100644
--- a/libgo/go/net/udp_test.go
+++ b/libgo/go/net/udp_test.go
@@ -87,3 +87,33 @@ func testWriteToPacketConn(t *testing.T, raddr string) {
t.Fatal("Write should fail")
}
}
+
+var udpConnLocalNameTests = []struct {
+ net string
+ laddr *UDPAddr
+}{
+ {"udp4", &UDPAddr{IP: IPv4(127, 0, 0, 1)}},
+ {"udp4", &UDPAddr{}},
+ {"udp4", nil},
+}
+
+func TestUDPConnLocalName(t *testing.T) {
+ if testing.Short() || !*testExternal {
+ t.Logf("skipping test to avoid external network")
+ return
+ }
+
+ for _, tt := range udpConnLocalNameTests {
+ c, err := ListenUDP(tt.net, tt.laddr)
+ if err != nil {
+ t.Errorf("ListenUDP failed: %v", err)
+ return
+ }
+ defer c.Close()
+ la := c.LocalAddr()
+ if a, ok := la.(*UDPAddr); !ok || a.Port == 0 {
+ t.Errorf("got %v; expected a proper address with non-zero port number", la)
+ return
+ }
+ }
+}