-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_test.go
49 lines (37 loc) · 1.34 KB
/
process_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
package main
import (
"fmt"
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)
func TestProcessSpawning(t *testing.T) {
process := StartProcess("echo", []string{"Hello"}, []string{})
code := waitAndRetrieveStatusCode(process)
assert.Equal(t, 0, code)
}
func TestProcessExitCodeSaving(t *testing.T) {
_ = os.Mkdir(".build", 0755)
process := StartProcess("/bin/true", []string{}, []string{})
_ = saveExitCode(waitAndRetrieveStatusCode(process), ".build/TestProcessExitCodeSaving")
actual, _ := os.ReadFile(".build/TestProcessExitCodeSaving")
assert.Equal(t, "0", string(actual))
}
func TestProcessExitCodeSaving_WhenProcessFails(t *testing.T) {
_ = os.Mkdir(".build", 0755)
process := StartProcess("/bin/false", []string{}, []string{})
_ = saveExitCode(waitAndRetrieveStatusCode(process), ".build/TestProcessExitCodeSaving")
actual, _ := os.ReadFile(".build/TestProcessExitCodeSaving")
assert.Equal(t, "1", string(actual))
}
func TestExtraPWDSetting(t *testing.T) {
_ = os.Mkdir(".build", 0755)
currentDir, _ := os.Getwd()
process := StartProcess("/bin/bash",
[]string{"-c", fmt.Sprintf("pwd > %v/.build/TestExtraPWDSetting", currentDir)},
[]string{"PWD=/tmp"})
_ = waitAndRetrieveStatusCode(process)
actual, _ := os.ReadFile(".build/TestExtraPWDSetting")
assert.Equal(t, "/tmp", strings.Trim(string(actual), "\n "))
}