Skip to content

Commit

Permalink
test: update tests for signal
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Dec 11, 2024
1 parent f8a2999 commit 82e0c35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 43 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ This is a personal project for me to explore and better understand the OCI Runti

**🗒️ To do** (items remaining for _me_ to consider this 'complete')

- [ ] Docker compatibility
- [ ] Tidy up dev env/workflow
- [ ] execve instead of fork/exec
- [ ] Implement seccomp
- [ ] Implement AppArmor
Expand Down
1 change: 1 addition & 0 deletions capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package capabilities_test
69 changes: 28 additions & 41 deletions signal/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,38 @@ import (
"github.com/stretchr/testify/assert"
)

var signalsInt = map[int]syscall.Signal{
1: syscall.SIGHUP,
2: syscall.SIGINT,
3: syscall.SIGQUIT,
6: syscall.SIGABRT,
9: syscall.SIGKILL,
15: syscall.SIGTERM,
17: syscall.SIGCHLD,
19: syscall.SIGSTOP,
20: syscall.SIGSTOP,
21: syscall.SIGSTOP,
22: syscall.SIGSTOP,
func TestFromInt(t *testing.T) {
sig, err := signal.FromInt(9)
assert.Equal(t, syscall.SIGKILL, sig)
assert.NoError(t, err)
}

var signalsStr = map[string]syscall.Signal{
"HUP": syscall.SIGHUP,
"SIGHUP": syscall.SIGHUP,
"INT": syscall.SIGINT,
"SIGINT": syscall.SIGINT,
"QUIT": syscall.SIGQUIT,
"SIGQUIT": syscall.SIGQUIT,
"ABRT": syscall.SIGABRT,
"SIGABRT": syscall.SIGABRT,
"KILL": syscall.SIGKILL,
"SIGKILL": syscall.SIGKILL,
"TERM": syscall.SIGTERM,
"SIGTERM": syscall.SIGTERM,
"CHLD": syscall.SIGCHLD,
"SIGCHLD": syscall.SIGCHLD,
"STOP": syscall.SIGSTOP,
"SIGSTOP": syscall.SIGSTOP,
func TestFromIntInvalid(t *testing.T) {
sig, err := signal.FromInt(99)
assert.Equal(t, syscall.Signal(-1), sig)
assert.Error(t, err)
}

func TestFromInt(t *testing.T) {
for k, v := range signalsInt {
sig, err := signal.FromInt(k)
assert.NoError(t, err)
assert.Equal(t, v, sig, "")
}
func TestFromStringNumber(t *testing.T) {
sig, err := signal.FromString("10")
assert.Equal(t, syscall.SIGUSR1, sig)
assert.NoError(t, err)
}

func TestFromStringShort(t *testing.T) {
sig, err := signal.FromString("CHLD")
assert.Equal(t, syscall.SIGCHLD, sig)
assert.NoError(t, err)
}

func TestFromStringLong(t *testing.T) {
sig, err := signal.FromString("SIGQUIT")
assert.Equal(t, syscall.SIGQUIT, sig)
assert.NoError(t, err)
}

func TestFromString(t *testing.T) {
for k, v := range signalsStr {
sig, err := signal.FromString(k)
assert.NoError(t, err)
assert.Equal(t, v, sig)
}
func TestFromStringInvalid(t *testing.T) {
sig, err := signal.FromString("something invalid")
assert.Equal(t, syscall.Signal(-1), sig)
assert.Error(t, err)
}

0 comments on commit 82e0c35

Please sign in to comment.