-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexec_test.go
64 lines (54 loc) · 1.57 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
package commander
import (
"github.com/WindomZ/testify/assert"
"strings"
"testing"
)
func Test_Exec_ExecPipeCommand(t *testing.T) {
stdout, stderr, err := Exec.ExecPipeCommand("")
assert.Error(t, err)
assert.Empty(t, stderr)
assert.Empty(t, stdout)
stdout, stderr, err = Exec.ExecPipeCommand("xxx", "xxx")
assert.Error(t, err)
assert.Empty(t, stderr)
assert.Empty(t, stdout)
stdout, stderr, err = Exec.ExecPipeCommand("ls")
assert.NoError(t, err)
assert.Empty(t, stderr)
assert.NotEmpty(t, stdout)
assert.True(t, strings.Contains(stdout, ".go"))
}
func Test_Exec_ExecStdCommand(t *testing.T) {
stdout, err := Exec.ExecStdCommand("")
assert.Error(t, err)
assert.Empty(t, stdout)
stdout, err = Exec.ExecStdCommand("xxx", "xxx")
assert.Error(t, err)
assert.Empty(t, stdout)
stdout, err = Exec.ExecStdCommand("ls", "-d")
assert.NoError(t, err)
assert.NotEmpty(t, stdout)
assert.True(t, strings.Contains(stdout, "."))
}
func Test_Exec_ExecPipeStatementCommand(t *testing.T) {
stdout, stderr, err := Exec.ExecPipeStatementCommand("ls -d")
assert.NoError(t, err)
assert.Empty(t, stderr)
assert.NotEmpty(t, stdout)
assert.True(t, strings.Contains(stdout, "."))
}
func Test_Exec_ExecStdStatementCommand(t *testing.T) {
stdout, err := Exec.ExecStdStatementCommand("ls -d")
assert.NoError(t, err)
assert.NotEmpty(t, stdout)
assert.True(t, strings.Contains(stdout, "."))
}
func Test_Exec_SplitCommandStatement(t *testing.T) {
strs := Exec.SplitCommandStatement(`rm -rf "$HOME/user/Download"`)
assert.Equal(t, strs, []string{
"rm",
"-rf",
"\"$HOME/user/Download\"",
})
}