-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor_test.go
More file actions
52 lines (44 loc) · 867 Bytes
/
Copy pathexecutor_test.go
File metadata and controls
52 lines (44 loc) · 867 Bytes
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
package main
import (
"bytes"
"fmt"
"io"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestRunCmd(t *testing.T) {
const refOut = `HELLO is ("hello")
BAR is (bar)
FOO is ( foo
with new line)
UNSET is ()
ADDED is (from original env)
EMPTY is ()
arguments are arg1=1 arg2=2
Exit code: 0
`
env, err := ReadDir("testdata/env/")
if err != nil {
fmt.Println(err)
}
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
var cmd []string
os.Setenv("ADDED", "from original env")
cmd = append(cmd, "/bin/bash", "testdata/echo.sh", "arg1=1", "arg2=2")
exitCode := RunCmd(cmd, env)
os.Unsetenv("ADDED")
fmt.Println("Exit code:", exitCode)
outC := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()
w.Close()
os.Stdout = oldStdout
out := <-outC
require.Equal(t, refOut, out)
}