MCPcopy Create free account
hub / github.com/docker/go-connections / TestUnixSocketWithOpts

Function TestUnixSocketWithOpts

sockets/unix_socket_unix_test.go:13–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestUnixSocketWithOpts(t *testing.T) {
14 socketPath := tempSocketPath(t)
15
16 uid, gid := os.Getuid(), os.Getgid()
17 perms := os.FileMode(0660)
18 l, err := NewUnixSocketWithOpts(socketPath, WithChown(uid, gid), WithChmod(perms))
19 if err != nil {
20 t.Fatal(err)
21 }
22 p, err := os.Stat(socketPath)
23 if err != nil {
24 t.Fatal(err)
25 }
26 if p.Mode().Perm() != perms {
27 t.Fatalf("unexpected file permissions: expected: %#o, got: %#o", perms, p.Mode().Perm())
28 }
29 if stat, ok := p.Sys().(*syscall.Stat_t); ok {
30 if stat.Uid != uint32(uid) || stat.Gid != uint32(gid) {
31 t.Fatalf("unexpected file ownership: expected: %d:%d, got: %d:%d", uid, gid, stat.Uid, stat.Gid)
32 }
33 }
34
35 defer func() { _ = l.Close() }()
36
37 echoStr := "hello"
38 runTest(t, socketPath, l, echoStr)
39}
40
41// TestUnixSocketWithOptsDefaultPermissions verifies that sockets created
42// without an explicit WithChmod option have permissions set to 0000.

Callers

nothing calls this directly

Calls 6

tempSocketPathFunction · 0.85
NewUnixSocketWithOptsFunction · 0.85
WithChownFunction · 0.85
WithChmodFunction · 0.85
runTestFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected