Commit 1fdb3e2e authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net: fix windows and plan9 build

Don't call unix-only function in test init.

R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/7778043
parent 69eb3457
...@@ -16,11 +16,11 @@ import ( ...@@ -16,11 +16,11 @@ import (
var connTests = []struct { var connTests = []struct {
net string net string
addr string addr func() string
}{ }{
{"tcp", "127.0.0.1:0"}, {"tcp", func() string { return "127.0.0.1:0" }},
{"unix", testUnixAddr()}, {"unix", testUnixAddr},
{"unixpacket", testUnixAddr()}, {"unixpacket", testUnixAddr},
} }
// someTimeout is used just to test that net.Conn implementations // someTimeout is used just to test that net.Conn implementations
...@@ -41,7 +41,8 @@ func TestConnAndListener(t *testing.T) { ...@@ -41,7 +41,8 @@ func TestConnAndListener(t *testing.T) {
} }
} }
ln, err := Listen(tt.net, tt.addr) addr := tt.addr()
ln, err := Listen(tt.net, addr)
if err != nil { if err != nil {
t.Fatalf("Listen failed: %v", err) t.Fatalf("Listen failed: %v", err)
} }
...@@ -51,7 +52,7 @@ func TestConnAndListener(t *testing.T) { ...@@ -51,7 +52,7 @@ func TestConnAndListener(t *testing.T) {
case "unix", "unixpacket": case "unix", "unixpacket":
os.Remove(addr) os.Remove(addr)
} }
}(ln, tt.net, tt.addr) }(ln, tt.net, addr)
ln.Addr() ln.Addr()
done := make(chan int) done := make(chan int)
......
...@@ -15,14 +15,20 @@ import ( ...@@ -15,14 +15,20 @@ import (
"time" "time"
) )
func strfunc(s string) func() string {
return func() string {
return s
}
}
var packetConnTests = []struct { var packetConnTests = []struct {
net string net string
addr1 string addr1 func() string
addr2 string addr2 func() string
}{ }{
{"udp", "127.0.0.1:0", "127.0.0.1:0"}, {"udp", strfunc("127.0.0.1:0"), strfunc("127.0.0.1:0")},
{"ip:icmp", "127.0.0.1", "127.0.0.1"}, {"ip:icmp", strfunc("127.0.0.1"), strfunc("127.0.0.1")},
{"unixgram", testUnixAddr(), testUnixAddr()}, {"unixgram", testUnixAddr, testUnixAddr},
} }
func TestPacketConn(t *testing.T) { func TestPacketConn(t *testing.T) {
...@@ -70,21 +76,22 @@ func TestPacketConn(t *testing.T) { ...@@ -70,21 +76,22 @@ func TestPacketConn(t *testing.T) {
continue continue
} }
c1, err := ListenPacket(tt.net, tt.addr1) addr1, addr2 := tt.addr1(), tt.addr2()
c1, err := ListenPacket(tt.net, addr1)
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
} }
defer closer(c1, netstr[0], tt.addr1, tt.addr2) defer closer(c1, netstr[0], addr1, addr2)
c1.LocalAddr() c1.LocalAddr()
c1.SetDeadline(time.Now().Add(100 * time.Millisecond)) c1.SetDeadline(time.Now().Add(100 * time.Millisecond))
c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
c1.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) c1.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
c2, err := ListenPacket(tt.net, tt.addr2) c2, err := ListenPacket(tt.net, addr2)
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
} }
defer closer(c2, netstr[0], tt.addr1, tt.addr2) defer closer(c2, netstr[0], addr1, addr2)
c2.LocalAddr() c2.LocalAddr()
c2.SetDeadline(time.Now().Add(100 * time.Millisecond)) c2.SetDeadline(time.Now().Add(100 * time.Millisecond))
c2.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) c2.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
...@@ -152,11 +159,12 @@ func TestConnAndPacketConn(t *testing.T) { ...@@ -152,11 +159,12 @@ func TestConnAndPacketConn(t *testing.T) {
continue continue
} }
c1, err := ListenPacket(tt.net, tt.addr1) addr1, addr2 := tt.addr1(), tt.addr2()
c1, err := ListenPacket(tt.net, addr1)
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
} }
defer closer(c1, netstr[0], tt.addr1, tt.addr2) defer closer(c1, netstr[0], addr1, addr2)
c1.LocalAddr() c1.LocalAddr()
c1.SetDeadline(time.Now().Add(100 * time.Millisecond)) c1.SetDeadline(time.Now().Add(100 * time.Millisecond))
c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment