mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/signal.TestTrap: use a subtest
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c855d411bf
commit
8f158db4ed
1 changed files with 14 additions and 12 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildTestBinary(t *testing.T, tmpdir string, prefix string) (string, string) {
|
func buildTestBinary(t *testing.T, tmpdir string, prefix string) (string, string) {
|
||||||
|
t.Helper()
|
||||||
tmpDir, err := ioutil.TempDir(tmpdir, prefix)
|
tmpDir, err := ioutil.TempDir(tmpdir, prefix)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
exePath := tmpDir + "/" + prefix
|
exePath := tmpDir + "/" + prefix
|
||||||
|
@ -41,24 +42,25 @@ func TestTrap(t *testing.T) {
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
for _, v := range sigmap {
|
for _, v := range sigmap {
|
||||||
cmd := exec.Command(exePath)
|
t.Run(v.name, func(t *testing.T) {
|
||||||
cmd.Env = append(os.Environ(), "SIGNAL_TYPE="+v.name)
|
cmd := exec.Command(exePath)
|
||||||
if v.multiple {
|
cmd.Env = append(os.Environ(), "SIGNAL_TYPE="+v.name)
|
||||||
cmd.Env = append(cmd.Env, "IF_MULTIPLE=1")
|
if v.multiple {
|
||||||
}
|
cmd.Env = append(cmd.Env, "IF_MULTIPLE=1")
|
||||||
err := cmd.Start()
|
}
|
||||||
assert.NilError(t, err)
|
err := cmd.Start()
|
||||||
err = cmd.Wait()
|
assert.NilError(t, err)
|
||||||
if e, ok := err.(*exec.ExitError); ok {
|
err = cmd.Wait()
|
||||||
|
e, ok := err.(*exec.ExitError)
|
||||||
|
assert.Assert(t, ok, "expected exec.ExitError, got %T", e)
|
||||||
|
|
||||||
code := e.Sys().(syscall.WaitStatus).ExitStatus()
|
code := e.Sys().(syscall.WaitStatus).ExitStatus()
|
||||||
if v.multiple {
|
if v.multiple {
|
||||||
assert.Check(t, is.DeepEqual(128+int(v.signal.(syscall.Signal)), code))
|
assert.Check(t, is.DeepEqual(128+int(v.signal.(syscall.Signal)), code))
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(99, code))
|
assert.Check(t, is.Equal(99, code))
|
||||||
}
|
}
|
||||||
continue
|
})
|
||||||
}
|
|
||||||
t.Fatal("process didn't end with any error")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue