-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathosexec_test.go
46 lines (39 loc) · 1.15 KB
/
osexec_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
package osexec_test
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/yyle88/osexec"
"github.com/yyle88/runpath"
)
func TestExec(t *testing.T) {
data, err := osexec.Exec("go", "version")
require.NoError(t, err)
t.Log(string(data))
require.NotEmpty(t, strings.TrimSpace(string(data)))
}
func TestExecInPath(t *testing.T) {
root := runpath.PARENT.Path()
data, err := osexec.ExecInPath(root, "ls", "-a")
require.NoError(t, err)
t.Log(string(data))
require.Contains(t, string(data), runpath.Name())
}
func TestExecInEnvs(t *testing.T) {
data, err := osexec.ExecInEnvs([]string{"a=100", "b=200"}, "bash", "-c", "echo $a")
require.NoError(t, err)
t.Log(string(data))
require.Equal(t, "100", strings.TrimSpace(string(data)))
}
func TestExecXshRun(t *testing.T) {
data, err := osexec.ExecXshRun("bash", "-c", "echo", "$HOME")
require.NoError(t, err)
t.Log(string(data))
require.NotEmpty(t, strings.TrimSpace(string(data)))
}
func TestExecXshRun1(t *testing.T) {
data, err := osexec.ExecXshRun("bash", "-c", "echo $HOME")
require.NoError(t, err)
t.Log(string(data))
require.NotEmpty(t, strings.TrimSpace(string(data)))
}