forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner_test.go
42 lines (34 loc) · 818 Bytes
/
runner_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
package cmdr_test
import (
"bytes"
"fmt"
"testing"
"github.com/gookit/goutil/sysutil/cmdr"
"github.com/gookit/goutil/testutil/assert"
)
func TestRunner_Run(t *testing.T) {
buf := new(bytes.Buffer)
rr := cmdr.NewRunner()
rr.Add(&cmdr.Task{
ID: "task1",
Cmd: cmdr.NewCmd("id").WithOutput(buf, buf),
})
rr.AddCmd(cmdr.NewCmd("ls").
AddArgs([]string{"-l", "-h"}).
WithOutput(buf, buf).
OnBefore(cmdr.PrintCmdline))
task, err := rr.Task("task1")
assert.NoErr(t, err)
assert.NoErr(t, task.Err())
assert.True(t, task.IsSuccess())
ids := rr.TaskIDs()
// dump.P(rr.TaskIDs())
assert.Len(t, ids, 2)
assert.NotEmpty(t, ids)
assert.Contains(t, ids, task.ID)
err = rr.Run()
assert.NoErr(t, err)
assert.NoErr(t, rr.Errs.One())
assert.True(t, rr.Errs.IsEmpty())
fmt.Println(buf.String())
}