-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_test.go
59 lines (50 loc) · 1.2 KB
/
command_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
package shell
import "testing"
const (
echoText1 = "next"
echoText2 = "test"
)
func TestCommand_Exec(t *testing.T) {
res, err := NewDefault().NewCommand("echo", echoText1).Exec(echoText2)
if err != nil {
t.Fatal(err)
}
echoRes := echoText1 + " " + echoText2
if res != echoRes {
t.Fatalf("unexpected result, expected: %s, got: %s", echoRes, res)
}
}
func TestNewCommand(t *testing.T) {
res, err := NewCommand("echo", echoText1).Exec(echoText2)
if err != nil {
t.Fatal(err)
}
echoRes := echoText1 + " " + echoText2
if res != echoRes {
t.Fatalf("unexpected result, expected: %s, got: %s", echoRes, res)
}
}
// This is a way to save your command and use it later
func ExampleNewCommand() {
// Creating a command from default shell
cmd := NewCommand("echo")
// ...
res, err := cmd.Exec("text 1")
// ...
res, err = cmd.Exec("text 2")
// ...
_, _ = res, err
}
// This is a way to save your command and use it later
func ExampleShell_NewCommand() {
// Creating specific shell
sh := New("/bin/bash", []string{"-c"})
// Creating a command from specific shell
cmd := sh.NewCommand("echo")
// ...
res, err := cmd.Exec("text 1")
// ...
res, err = cmd.Exec("text 2")
// ...
_, _ = res, err
}