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) {
|
||||
t.Helper()
|
||||
tmpDir, err := ioutil.TempDir(tmpdir, prefix)
|
||||
assert.NilError(t, err)
|
||||
exePath := tmpDir + "/" + prefix
|
||||
|
@ -41,24 +42,25 @@ func TestTrap(t *testing.T) {
|
|||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
for _, v := range sigmap {
|
||||
cmd := exec.Command(exePath)
|
||||
cmd.Env = append(os.Environ(), "SIGNAL_TYPE="+v.name)
|
||||
if v.multiple {
|
||||
cmd.Env = append(cmd.Env, "IF_MULTIPLE=1")
|
||||
}
|
||||
err := cmd.Start()
|
||||
assert.NilError(t, err)
|
||||
err = cmd.Wait()
|
||||
if e, ok := err.(*exec.ExitError); ok {
|
||||
t.Run(v.name, func(t *testing.T) {
|
||||
cmd := exec.Command(exePath)
|
||||
cmd.Env = append(os.Environ(), "SIGNAL_TYPE="+v.name)
|
||||
if v.multiple {
|
||||
cmd.Env = append(cmd.Env, "IF_MULTIPLE=1")
|
||||
}
|
||||
err := cmd.Start()
|
||||
assert.NilError(t, err)
|
||||
err = cmd.Wait()
|
||||
e, ok := err.(*exec.ExitError)
|
||||
assert.Assert(t, ok, "expected exec.ExitError, got %T", e)
|
||||
|
||||
code := e.Sys().(syscall.WaitStatus).ExitStatus()
|
||||
if v.multiple {
|
||||
assert.Check(t, is.DeepEqual(128+int(v.signal.(syscall.Signal)), code))
|
||||
} else {
|
||||
assert.Check(t, is.Equal(99, code))
|
||||
}
|
||||
continue
|
||||
}
|
||||
t.Fatal("process didn't end with any error")
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue