-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsignal_test.go
More file actions
45 lines (41 loc) · 826 Bytes
/
signal_test.go
File metadata and controls
45 lines (41 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"io"
"os"
"testing"
)
type testProcess struct {
receivedSignals []os.Signal
reject bool
}
func (t *testProcess) Signal(sig os.Signal) error {
if t.reject {
return fmt.Errorf("rejected")
}
t.receivedSignals = append(t.receivedSignals, sig)
return nil
}
func TestSendSignal(t *testing.T) {
defer func() {
data := recover().(exitData)
if data.code != 0 {
t.Fail()
}
}()
_, stderr := io.Pipe()
args := []string{"--pid", "1", "--signal", "TERM"}
testProcess := &testProcess{}
signal(stderr, args, exit, func(pid int) (Process, error) {
if pid != 1 {
return nil, fmt.Errorf("invalid PID")
}
return testProcess, nil
})
if len(testProcess.receivedSignals) != 1 {
t.FailNow()
}
if testProcess.receivedSignals[0].String() != "TERM" {
t.FailNow()
}
}