(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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. |
nothing calls this directly
no test coverage detected