OLD | NEW |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build !plan9,!windows | 5 // +build !plan9,!windows |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
11 "io/ioutil" | |
12 "os" | 11 "os" |
13 "reflect" | 12 "reflect" |
14 "runtime" | 13 "runtime" |
15 "syscall" | 14 "syscall" |
16 "testing" | 15 "testing" |
17 "time" | 16 "time" |
18 ) | 17 ) |
19 | 18 |
20 // testUnixAddr uses ioutil.TempFile to get a name that is unique. | |
21 func testUnixAddr() string { | |
22 f, err := ioutil.TempFile("", "nettest") | |
23 if err != nil { | |
24 panic(err) | |
25 } | |
26 addr := f.Name() | |
27 f.Close() | |
28 os.Remove(addr) | |
29 return addr | |
30 } | |
31 | |
32 func TestReadUnixgramWithUnnamedSocket(t *testing.T) { | 19 func TestReadUnixgramWithUnnamedSocket(t *testing.T) { |
33 addr := testUnixAddr() | 20 addr := testUnixAddr() |
34 la, err := ResolveUnixAddr("unixgram", addr) | 21 la, err := ResolveUnixAddr("unixgram", addr) |
35 if err != nil { | 22 if err != nil { |
36 t.Fatalf("ResolveUnixAddr failed: %v", err) | 23 t.Fatalf("ResolveUnixAddr failed: %v", err) |
37 } | 24 } |
38 c, err := ListenUnixgram("unixgram", la) | 25 c, err := ListenUnixgram("unixgram", la) |
39 if err != nil { | 26 if err != nil { |
40 t.Fatalf("ListenUnixgram failed: %v", err) | 27 t.Fatalf("ListenUnixgram failed: %v", err) |
41 } | 28 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 c2, err := DialUnix("unixgram", nil, autoAddr) | 135 c2, err := DialUnix("unixgram", nil, autoAddr) |
149 if err != nil { | 136 if err != nil { |
150 t.Fatalf("DialUnix failed: %v", err) | 137 t.Fatalf("DialUnix failed: %v", err) |
151 } | 138 } |
152 defer c2.Close() | 139 defer c2.Close() |
153 | 140 |
154 if !reflect.DeepEqual(c1.LocalAddr(), c2.RemoteAddr()) { | 141 if !reflect.DeepEqual(c1.LocalAddr(), c2.RemoteAddr()) { |
155 t.Fatalf("Expected autobind address %v, got %v", c1.LocalAddr(),
c2.RemoteAddr()) | 142 t.Fatalf("Expected autobind address %v, got %v", c1.LocalAddr(),
c2.RemoteAddr()) |
156 } | 143 } |
157 } | 144 } |
OLD | NEW |