mirror of
https://github.com/golang/go
synced 2024-11-23 16:50:06 -07:00
net: drop unnecessary indirection from PacketConn tests
LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/83880043
This commit is contained in:
parent
22bc710fe4
commit
72dbc4ccc8
@ -15,12 +15,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func strfunc(s string) func() string {
|
|
||||||
return func() string {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) {
|
func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) {
|
||||||
switch net {
|
switch net {
|
||||||
case "udp":
|
case "udp":
|
||||||
@ -62,12 +56,12 @@ func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) {
|
|||||||
|
|
||||||
var packetConnTests = []struct {
|
var packetConnTests = []struct {
|
||||||
net string
|
net string
|
||||||
addr1 func() string
|
addr1 string
|
||||||
addr2 func() string
|
addr2 string
|
||||||
}{
|
}{
|
||||||
{"udp", strfunc("127.0.0.1:0"), strfunc("127.0.0.1:0")},
|
{"udp", "127.0.0.1:0", "127.0.0.1:0"},
|
||||||
{"ip:icmp", strfunc("127.0.0.1"), strfunc("127.0.0.1")},
|
{"ip:icmp", "127.0.0.1", "127.0.0.1"},
|
||||||
{"unixgram", testUnixAddr, testUnixAddr},
|
{"unixgram", testUnixAddr(), testUnixAddr()},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPacketConn(t *testing.T) {
|
func TestPacketConn(t *testing.T) {
|
||||||
@ -88,22 +82,21 @@ func TestPacketConn(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
addr1, addr2 := tt.addr1(), tt.addr2()
|
c1, err := ListenPacket(tt.net, tt.addr1)
|
||||||
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], addr1, addr2)
|
defer closer(c1, netstr[0], tt.addr1, tt.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, addr2)
|
c2, err := ListenPacket(tt.net, tt.addr2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ListenPacket failed: %v", err)
|
t.Fatalf("ListenPacket failed: %v", err)
|
||||||
}
|
}
|
||||||
defer closer(c2, netstr[0], addr1, addr2)
|
defer closer(c2, netstr[0], tt.addr1, tt.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))
|
||||||
@ -145,12 +138,11 @@ func TestConnAndPacketConn(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
addr1, addr2 := tt.addr1(), tt.addr2()
|
c1, err := ListenPacket(tt.net, tt.addr1)
|
||||||
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], addr1, addr2)
|
defer closer(c1, netstr[0], tt.addr1, tt.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))
|
||||||
|
Loading…
Reference in New Issue
Block a user