1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/signal/signal_linux_test.go
Sebastiaan van Stijn af2a11f316
TestCatchAll, TestStopCatch: remove unneeded goroutine
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-15 00:41:28 +01:00

48 lines
1.1 KiB
Go

// +build darwin linux
package signal // import "github.com/docker/docker/pkg/signal"
import (
"os"
"syscall"
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestCatchAll(t *testing.T) {
sigs := make(chan os.Signal, 1)
CatchAll(sigs)
defer StopCatch(sigs)
listOfSignals := map[string]string{
"CONT": syscall.SIGCONT.String(),
"HUP": syscall.SIGHUP.String(),
"CHLD": syscall.SIGCHLD.String(),
"ILL": syscall.SIGILL.String(),
"FPE": syscall.SIGFPE.String(),
"CLD": syscall.SIGCLD.String(),
}
for sigStr := range listOfSignals {
if signal, ok := SignalMap[sigStr]; ok {
syscall.Kill(syscall.Getpid(), signal)
s := <-sigs
assert.Check(t, is.Equal(s.String(), signal.String()))
}
}
}
func TestStopCatch(t *testing.T) {
signal := SignalMap["HUP"]
channel := make(chan os.Signal, 1)
CatchAll(channel)
syscall.Kill(syscall.Getpid(), signal)
signalString := <-channel
assert.Check(t, is.Equal(signalString.String(), signal.String()))
StopCatch(channel)
_, ok := <-channel
assert.Check(t, is.Equal(ok, false))
}