Skip to content

Commit eb34a0b

Browse files
authored
Merge pull request #77 from thaJeztah/run_tests
CircleCI: run unit tests, and add test for Socket Permissions
2 parents 09f4792 + 7eb1169 commit eb34a0b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

circle.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
- run:
2323
name: gofmt
2424
command: test -z "$(gofmt -s -l . | tee /dev/stderr)"
25+
- run:
26+
name: Run tests
27+
command: sudo -E env PATH=$PATH go test -v ./...
28+
environment:
29+
GOOS: linux
2530
# make sure that it passes build on both Linux and Windows
2631
- run:
2732
name: Build for Linux

sockets/unix_socket_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net"
66
"os"
7+
"syscall"
78
"testing"
89
)
910

@@ -47,12 +48,25 @@ func TestNewUnixSocket(t *testing.T) {
4748

4849
func TestUnixSocketWithOpts(t *testing.T) {
4950
uid, gid := os.Getuid(), os.Getgid()
51+
perms := os.FileMode(0660)
5052
path := "/tmp/test.sock"
5153
echoStr := "hello"
52-
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(0660))
54+
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(perms))
5355
if err != nil {
5456
t.Fatal(err)
5557
}
5658
defer l.Close()
59+
p, err := os.Stat(path)
60+
if err != nil {
61+
t.Fatal(err)
62+
}
63+
if p.Mode().Perm() != perms {
64+
t.Fatalf("unexpected file permissions: expected: %#o, got: %#o", perms, p.Mode().Perm())
65+
}
66+
if stat, ok := p.Sys().(*syscall.Stat_t); ok {
67+
if stat.Uid != uint32(uid) || stat.Gid != uint32(gid) {
68+
t.Fatalf("unexpected file ownership: expected: %d:%d, got: %d:%d", uid, gid, stat.Uid, stat.Gid)
69+
}
70+
}
5771
runTest(t, path, l, echoStr)
5872
}

0 commit comments

Comments
 (0)