1
0
mirror of https://github.com/golang/go synced 2024-09-25 05:10:12 -06: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:
Brad Fitzpatrick 2013-03-13 07:42:55 -07:00
parent 69eb345727
commit 1fdb3e2ed6
2 changed files with 26 additions and 17 deletions

View File

@ -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)

View File

@ -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))