mirror of
https://github.com/golang/go
synced 2024-11-12 08:20:22 -07:00
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
This commit is contained in:
parent
69eb345727
commit
1fdb3e2ed6
@ -16,11 +16,11 @@ import (
|
||||
|
||||
var connTests = []struct {
|
||||
net string
|
||||
addr string
|
||||
addr func() string
|
||||
}{
|
||||
{"tcp", "127.0.0.1:0"},
|
||||
{"unix", testUnixAddr()},
|
||||
{"unixpacket", testUnixAddr()},
|
||||
{"tcp", func() string { return "127.0.0.1:0" }},
|
||||
{"unix", testUnixAddr},
|
||||
{"unixpacket", testUnixAddr},
|
||||
}
|
||||
|
||||
// someTimeout is used just to test that net.Conn implementations
|
||||
@ -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 {
|
||||
t.Fatalf("Listen failed: %v", err)
|
||||
}
|
||||
@ -51,7 +52,7 @@ func TestConnAndListener(t *testing.T) {
|
||||
case "unix", "unixpacket":
|
||||
os.Remove(addr)
|
||||
}
|
||||
}(ln, tt.net, tt.addr)
|
||||
}(ln, tt.net, addr)
|
||||
ln.Addr()
|
||||
|
||||
done := make(chan int)
|
||||
|
@ -15,14 +15,20 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func strfunc(s string) func() string {
|
||||
return func() string {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
var packetConnTests = []struct {
|
||||
net string
|
||||
addr1 string
|
||||
addr2 string
|
||||
addr1 func() string
|
||||
addr2 func() string
|
||||
}{
|
||||
{"udp", "127.0.0.1:0", "127.0.0.1:0"},
|
||||
{"ip:icmp", "127.0.0.1", "127.0.0.1"},
|
||||
{"unixgram", testUnixAddr(), testUnixAddr()},
|
||||
{"udp", strfunc("127.0.0.1:0"), strfunc("127.0.0.1:0")},
|
||||
{"ip:icmp", strfunc("127.0.0.1"), strfunc("127.0.0.1")},
|
||||
{"unixgram", testUnixAddr, testUnixAddr},
|
||||
}
|
||||
|
||||
func TestPacketConn(t *testing.T) {
|
||||
@ -70,21 +76,22 @@ func TestPacketConn(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
c1, err := ListenPacket(tt.net, tt.addr1)
|
||||
addr1, addr2 := tt.addr1(), tt.addr2()
|
||||
c1, err := ListenPacket(tt.net, addr1)
|
||||
if err != nil {
|
||||
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.SetDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
c1.SetReadDeadline(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 {
|
||||
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.SetDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
c2.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
@ -152,11 +159,12 @@ func TestConnAndPacketConn(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
c1, err := ListenPacket(tt.net, tt.addr1)
|
||||
addr1, addr2 := tt.addr1(), tt.addr2()
|
||||
c1, err := ListenPacket(tt.net, addr1)
|
||||
if err != nil {
|
||||
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.SetDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
|
Loading…
Reference in New Issue
Block a user