-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
exec_unix_test.go
43 lines (32 loc) · 756 Bytes
/
exec_unix_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
//go:build linux || darwin
package execute
import (
"context"
"os"
"path"
"testing"
)
func Test_Exec_WithSpaceInCommandPath(t *testing.T) {
tmp, err := os.MkdirTemp(os.TempDir(), "exec test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
// copy /bin/echo to a new path with a space in it
data, err := os.ReadFile("/bin/echo")
if err != nil {
t.Fatal(err)
}
newPath := path.Join(tmp, "echo")
if err := os.WriteFile(newPath, data, 0755); err != nil {
t.Fatal(err)
}
task := ExecTask{Command: newPath, Args: []string{"hello world"}}
res, err := task.Execute(context.Background())
if err != nil {
t.Fatal(err)
}
if res.Stdout != "hello world\n" {
t.Fatalf("want %q, got %q", "hello world\n", res.Stdout)
}
}