-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexec_test.go
66 lines (59 loc) · 1.37 KB
/
exec_test.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package exec
import (
"bytes"
"fmt"
"github.com/shxsun/monitor"
"testing"
"time"
)
func TestNormal(t *testing.T) {
cmd := Command("echo", "-n", "hello")
output, err := cmd.Output()
if err != nil {
t.Errorf("expect normal, but got error: %s\n", err.Error())
}
if string(output) != "hello" {
t.Errorf("expect 'hello', but got: %s\n", string(output))
}
}
func TestNormalTimeout(t *testing.T) {
cmd := Command("sleep", "2")
err := cmd.Start()
if err != nil {
t.Error(err)
}
err = cmd.WaitTimeout(time.Second * 1)
if err == nil {
t.Errorf("expect ErrTimeout, but err is nil")
}
if err != ErrTimeout {
t.Errorf("expect ErrTimeout, but receive %s", err.Error())
}
}
func TestTimeout(t *testing.T) {
cmd := Command("sleep", "2")
cmd.Timeout = time.Second * 1
_, err := cmd.Output()
if err != ErrTimeout {
t.Errorf("expect ErrTimeout, but got: %s\n", err.Error())
}
}
func TestKillAll(t *testing.T) {
b := bytes.NewBuffer(nil)
cmd := Command("sh", "testdata/killall_test.sh")
cmd.IsClean = true
cmd.Stdout = b
cmd.Start()
time.Sleep(200 * time.Millisecond)
var pid int
fmt.Sscanf(string(b.Bytes()), "%d", &pid)
cmd.KillAll()
minfo, err := monitor.Pid(pid + 1) // main quit, sleep is main_pid + 1
fmt.Println(minfo, err) // FIXME: not finished
}
// FIXME
func TestCleanNormal(t *testing.T) {
}
// FIXME
func TestCleanTimeout(t *testing.T) {
}