OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / net / internal / socket / socket_test.go
1 // Copyright 2017 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 // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
6
7 package socket_test
8
9 import (
10         "net"
11         "runtime"
12         "syscall"
13         "testing"
14
15         "golang.org/x/net/internal/nettest"
16         "golang.org/x/net/internal/socket"
17 )
18
19 func TestSocket(t *testing.T) {
20         t.Run("Option", func(t *testing.T) {
21                 testSocketOption(t, &socket.Option{Level: syscall.SOL_SOCKET, Name: syscall.SO_RCVBUF, Len: 4})
22         })
23 }
24
25 func testSocketOption(t *testing.T, so *socket.Option) {
26         c, err := nettest.NewLocalPacketListener("udp")
27         if err != nil {
28                 t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
29         }
30         defer c.Close()
31         cc, err := socket.NewConn(c.(net.Conn))
32         if err != nil {
33                 t.Fatal(err)
34         }
35         const N = 2048
36         if err := so.SetInt(cc, N); err != nil {
37                 t.Fatal(err)
38         }
39         n, err := so.GetInt(cc)
40         if err != nil {
41                 t.Fatal(err)
42         }
43         if n < N {
44                 t.Fatalf("got %d; want greater than or equal to %d", n, N)
45         }
46 }