Skip to content

Commit

Permalink
Merge pull request #77 from thaJeztah/run_tests
Browse files Browse the repository at this point in the history
CircleCI: run unit tests, and add test for Socket Permissions
  • Loading branch information
thaJeztah authored Mar 15, 2021
2 parents 09f4792 + 7eb1169 commit eb34a0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
- run:
name: gofmt
command: test -z "$(gofmt -s -l . | tee /dev/stderr)"
- run:
name: Run tests
command: sudo -E env PATH=$PATH go test -v ./...
environment:
GOOS: linux
# make sure that it passes build on both Linux and Windows
- run:
name: Build for Linux
Expand Down
16 changes: 15 additions & 1 deletion sockets/unix_socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
"syscall"
"testing"
)

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

func TestUnixSocketWithOpts(t *testing.T) {
uid, gid := os.Getuid(), os.Getgid()
perms := os.FileMode(0660)
path := "/tmp/test.sock"
echoStr := "hello"
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(0660))
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(perms))
if err != nil {
t.Fatal(err)
}
defer l.Close()
p, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if p.Mode().Perm() != perms {
t.Fatalf("unexpected file permissions: expected: %#o, got: %#o", perms, p.Mode().Perm())
}
if stat, ok := p.Sys().(*syscall.Stat_t); ok {
if stat.Uid != uint32(uid) || stat.Gid != uint32(gid) {
t.Fatalf("unexpected file ownership: expected: %d:%d, got: %d:%d", uid, gid, stat.Uid, stat.Gid)
}
}
runTest(t, path, l, echoStr)
}

0 comments on commit eb34a0b

Please sign in to comment.