Source file
src/net/unixsock_windows_test.go
1
2
3
4
5
6
7 package net
8
9 import (
10 "internal/syscall/windows"
11 "os"
12 "reflect"
13 "testing"
14 )
15
16 func TestUnixConnLocalWindows(t *testing.T) {
17 if !windows.SupportUnixSocket() {
18 t.Skip("unix test")
19 }
20 handler := func(ls *localServer, ln Listener) {}
21 for _, laddr := range []string{"", testUnixAddr(t)} {
22 laddr := laddr
23 taddr := testUnixAddr(t)
24 ta, err := ResolveUnixAddr("unix", taddr)
25 if err != nil {
26 t.Fatal(err)
27 }
28 ln, err := ListenUnix("unix", ta)
29 if err != nil {
30 t.Fatal(err)
31 }
32 ls := (&streamListener{Listener: ln}).newLocalServer()
33 defer ls.teardown()
34 if err := ls.buildup(handler); err != nil {
35 t.Fatal(err)
36 }
37
38 la, err := ResolveUnixAddr("unix", laddr)
39 if err != nil {
40 t.Fatal(err)
41 }
42 c, err := DialUnix("unix", la, ta)
43 if err != nil {
44 t.Fatal(err)
45 }
46 defer func() {
47 c.Close()
48 if la != nil {
49 defer os.Remove(laddr)
50 }
51 }()
52 if _, err := c.Write([]byte("UNIXCONN LOCAL AND REMOTE NAME TEST")); err != nil {
53 t.Fatal(err)
54 }
55
56 if laddr == "" {
57 laddr = "@"
58 }
59 var connAddrs = [3]struct{ got, want Addr }{
60 {ln.Addr(), ta},
61 {c.LocalAddr(), &UnixAddr{Name: laddr, Net: "unix"}},
62 {c.RemoteAddr(), ta},
63 }
64 for _, ca := range connAddrs {
65 if !reflect.DeepEqual(ca.got, ca.want) {
66 t.Fatalf("got %#v, expected %#v", ca.got, ca.want)
67 }
68 }
69 }
70 }
71
72 func TestModeSocket(t *testing.T) {
73 if !windows.SupportUnixSocket() {
74 t.Skip("unix test")
75 }
76
77 addr := testUnixAddr(t)
78
79 l, err := Listen("unix", addr)
80 if err != nil {
81 t.Fatal(err)
82 }
83 defer l.Close()
84
85 stat, err := os.Stat(addr)
86 if err != nil {
87 t.Fatal(err)
88 }
89
90 mode := stat.Mode()
91 if mode&os.ModeSocket == 0 {
92 t.Fatalf("%v should have ModeSocket", mode)
93 }
94 }
95
View as plain text