-
Notifications
You must be signed in to change notification settings - Fork 24
/
option_test.go
71 lines (63 loc) · 1.34 KB
/
option_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2016 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tcp_test
import (
"math/rand"
"net"
"os"
"runtime"
"testing"
"github.com/mikioh/tcp"
)
func TestOptionWithVariousBufferLengths(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
c, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
t.Fatal(err)
}
defer c.Close()
tc, err := tcp.NewConn(c)
if err != nil {
t.Fatal(err)
}
for i := 0; i < 256; i++ {
level, name := rand.Int(), rand.Int()
b := make([]byte, i)
tc.Option(level, name, b)
}
}
func TestOriginalDst(t *testing.T) {
switch runtime.GOOS {
case "linux":
case "darwin", "dragonfly", "freebsd", "openbsd":
if os.Getuid() != 0 {
t.Skip("must be root")
}
default:
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
for _, address := range []string{"127.0.0.1:0"} {
ln, err := net.Listen("tcp", address)
if err != nil {
t.Fatal(err)
}
defer ln.Close()
c, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
t.Fatal(err)
}
defer c.Close()
tc, err := tcp.NewConn(c)
if err != nil {
t.Fatal(err)
}
if _, err := tc.OriginalDst(); err != nil {
t.Log(err)
}
}
}