1
1
package execute
2
2
3
3
import (
4
+ "bytes"
4
5
"os"
5
6
"strings"
6
7
"testing"
@@ -25,6 +26,49 @@ func TestExec_WithShell(t *testing.T) {
25
26
}
26
27
}
27
28
29
+ func TestExec_CatTransformString (t * testing.T ) {
30
+ input := "1 line 1"
31
+
32
+ reader := bytes .NewReader ([]byte (input ))
33
+ want := " 1\t 1 line 1"
34
+
35
+ task := ExecTask {Command : "cat" , Shell : false , Args : []string {"-b" }, Stdin : reader }
36
+ res , err := task .Execute ()
37
+ if err != nil {
38
+ t .Errorf (err .Error ())
39
+ t .Fail ()
40
+ }
41
+
42
+ if res .Stdout != want {
43
+ t .Errorf ("want %q, got %q" , want , res .Stdout )
44
+ t .Fail ()
45
+ }
46
+ }
47
+
48
+ func TestExec_CatWC (t * testing.T ) {
49
+ input := `this
50
+ has
51
+ four
52
+ lines
53
+ `
54
+
55
+ reader := bytes .NewReader ([]byte (input ))
56
+ want := "4"
57
+
58
+ task := ExecTask {Command : "wc" , Shell : false , Args : []string {"-l" }, Stdin : reader }
59
+ res , err := task .Execute ()
60
+ if err != nil {
61
+ t .Errorf (err .Error ())
62
+ t .Fail ()
63
+ }
64
+
65
+ got := strings .TrimSpace (res .Stdout )
66
+ if got != want {
67
+ t .Errorf ("want %q, got %q" , want , got )
68
+ t .Fail ()
69
+ }
70
+ }
71
+
28
72
func TestExec_WithEnvVars (t * testing.T ) {
29
73
task := ExecTask {Command : "env" , Shell : false , Env : []string {"GOTEST=1" , "GOTEST2=2" }}
30
74
res , err := task .Execute ()
@@ -42,7 +86,6 @@ func TestExec_WithEnvVars(t *testing.T) {
42
86
t .Errorf ("want env to show GOTEST2=2 since we passed that variable" )
43
87
t .Fail ()
44
88
}
45
-
46
89
}
47
90
48
91
func TestExec_WithEnvVarsInheritedFromParent (t * testing.T ) {
0 commit comments