-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.go
55 lines (47 loc) · 1.45 KB
/
run_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
package golbin
import (
"strings"
"testing"
)
func TestConsoleRun(t *testing.T) {
kon := Console{Command: "echo 'Hello Shell!'"}
kon.Run()
if strings.Trim(kon.StdOutput, " ") != "Hello Shell!\n" {
t.Errorf("FAILED to echo required string. Got: '%s'", kon.StdOutput)
}
}
func TestConsoleRunFailure(t *testing.T) {
kon := Console{Command: "no-cmd-echo 'Hello Shell!'"}
kon.Run()
hasError := false
for _, out := range strings.Fields(kon.StdOutput) {
if out == "Error:" {
hasError = true
}
}
if !hasError {
t.Errorf("FAILED to echo required string. Got: '%s'", kon.StdOutput)
}
}
func TestExecOutput(t *testing.T) {
out := ExecOutput("echo 'Hello Shell!'")
if strings.Trim(out, " ") != "Hello Shell!\n" {
t.Errorf("FAILED to echo required string. Got: '%s'", out)
}
}
func TestExec(t *testing.T) {
out, err := Exec("echo 'Hello Shell!'")
if strings.Trim(out, " ") != "Hello Shell!\n" || err != nil {
t.Errorf("FAILED to echo required string. Got: '%s' & '%s'", out, err.Error())
}
out, err = Exec("should-not-echo 'Hello Shell!'")
if strings.Trim(out, " ") != "" || err == nil {
t.Errorf("FAILED to echo required string. Got: '%s' & '%s'", out, err.Error())
}
}
func TestExecWithEnv(t *testing.T) {
out, err := ExecWithEnv("bash -c 'echo $TEMP_GOLBIN_VAR'", map[string]string{"TEMP_GOLBIN_VAR": "Hey!"})
if strings.Trim(out, " ") != "Hey!\n" || err != nil {
t.Errorf("FAILED to echo required string. Got: '%s' & '%s'", out, err.Error())
}
}