Skip to content

Commit 0bfab66

Browse files
tklausergopherbot
authored andcommitted
ipv4, ipv6: drop redundant skip checks based on GOOS
All the dropped platforms either don't support raw sockets or the tests pass sucessfully (e.g. ipv4.TestPacketConnReadWriteMulticastICMP on solaris), so the tests can rely on being skipped due to !nettest.SupportsRawSocket(). Also check for errNotImplemented to cover cases where functionality is not available on windows. Change-Id: Ic9107a7ca16e9d9faed4991e1148b493c646ea7d Reviewed-on: https://go-review.googlesource.com/c/net/+/489155 Run-TryBot: Tobias Klauser <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Tobias Klauser <[email protected]>
1 parent 938ff15 commit 0bfab66

13 files changed

+35
-55
lines changed

ipv4/export_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package ipv4
6+
7+
var ErrNotImplemented = errNotImplemented

ipv4/helper_posix_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
package ipv4_test
99

1010
import (
11+
"errors"
1112
"os"
1213
"syscall"
14+
15+
"golang.org/x/net/ipv4"
1316
)
1417

1518
func protocolNotSupported(err error) bool {
@@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool {
2831
}
2932
}
3033
}
31-
return false
34+
return errors.Is(err, ipv4.ErrNotImplemented)
3235
}

ipv4/multicast_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ var packetConnReadWriteMulticastICMPTests = []struct {
131131
}
132132

133133
func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
134-
switch runtime.GOOS {
135-
case "fuchsia", "hurd", "illumos", "js", "nacl", "plan9", "solaris", "wasip1", "windows":
136-
t.Skipf("not supported on %s", runtime.GOOS)
137-
}
138134
if !nettest.SupportsRawSocket() {
139135
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
140136
}
@@ -261,10 +257,6 @@ var rawConnReadWriteMulticastICMPTests = []struct {
261257
}
262258

263259
func TestRawConnReadWriteMulticastICMP(t *testing.T) {
264-
switch runtime.GOOS {
265-
case "fuchsia", "hurd", "illumos", "js", "nacl", "plan9", "solaris", "wasip1", "windows":
266-
t.Skipf("not supported on %s", runtime.GOOS)
267-
}
268260
if testing.Short() {
269261
t.Skip("to avoid external network")
270262
}

ipv4/multicastlistener_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
171171
}
172172

173173
func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) {
174-
switch runtime.GOOS {
175-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
176-
t.Skipf("not supported on %s", runtime.GOOS)
177-
}
178174
if testing.Short() {
179175
t.Skip("to avoid external network")
180176
}
@@ -216,10 +212,6 @@ func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) {
216212
}
217213

218214
func TestIPPerInterfaceSingleRawConnWithSingleGroupListener(t *testing.T) {
219-
switch runtime.GOOS {
220-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
221-
t.Skipf("not supported on %s", runtime.GOOS)
222-
}
223215
if testing.Short() {
224216
t.Skip("to avoid external network")
225217
}

ipv4/multicastsockopt_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ var rawConnMulticastSocketOptionTests = []struct {
6565
}
6666

6767
func TestRawConnMulticastSocketOptions(t *testing.T) {
68-
switch runtime.GOOS {
69-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "zos":
70-
t.Skipf("not supported on %s", runtime.GOOS)
71-
}
7268
if !nettest.SupportsRawSocket() {
7369
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
7470
}

ipv4/unicast_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
8484
}
8585

8686
func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
87-
switch runtime.GOOS {
88-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
89-
t.Skipf("not supported on %s", runtime.GOOS)
90-
}
9187
if !nettest.SupportsRawSocket() {
9288
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
9389
}
@@ -179,10 +175,6 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
179175
}
180176

181177
func TestRawConnReadWriteUnicastICMP(t *testing.T) {
182-
switch runtime.GOOS {
183-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
184-
t.Skipf("not supported on %s", runtime.GOOS)
185-
}
186178
if !nettest.SupportsRawSocket() {
187179
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
188180
}

ipv4/unicastsockopt_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ func TestPacketConnUnicastSocketOptions(t *testing.T) {
8585
}
8686

8787
func TestRawConnUnicastSocketOptions(t *testing.T) {
88-
switch runtime.GOOS {
89-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
90-
t.Skipf("not supported on %s", runtime.GOOS)
91-
}
9288
if !nettest.SupportsRawSocket() {
9389
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
9490
}

ipv6/export_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package ipv6
6+
7+
var ErrNotImplemented = errNotImplemented

ipv6/helper_posix_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
package ipv6_test
99

1010
import (
11+
"errors"
1112
"os"
1213
"syscall"
14+
15+
"golang.org/x/net/ipv6"
1316
)
1417

1518
func protocolNotSupported(err error) bool {
@@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool {
2831
}
2932
}
3033
}
31-
return false
34+
return errors.Is(err, ipv6.ErrNotImplemented)
3235
}

ipv6/icmp_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package ipv6_test
66

77
import (
8+
"errors"
89
"net"
910
"reflect"
1011
"runtime"
@@ -60,10 +61,6 @@ func TestICMPFilter(t *testing.T) {
6061
}
6162

6263
func TestSetICMPFilter(t *testing.T) {
63-
switch runtime.GOOS {
64-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
65-
t.Skipf("not supported on %s", runtime.GOOS)
66-
}
6764
if !nettest.SupportsIPv6() {
6865
t.Skip("ipv6 is not supported")
6966
}
@@ -83,9 +80,12 @@ func TestSetICMPFilter(t *testing.T) {
8380
f.SetAll(true)
8481
f.Accept(ipv6.ICMPTypeEchoRequest)
8582
f.Accept(ipv6.ICMPTypeEchoReply)
86-
if err := p.SetICMPFilter(&f); err != nil {
83+
if err := p.SetICMPFilter(&f); errors.Is(err, ipv6.ErrNotImplemented) {
84+
t.Skipf("setting ICMP filter not supported: %v", err)
85+
} else if err != nil {
8786
t.Fatal(err)
8887
}
88+
8989
kf, err := p.ICMPFilter()
9090
if err != nil {
9191
t.Fatal(err)

0 commit comments

Comments
 (0)