@@ -3,6 +3,7 @@ package integration
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "crypto/rand"
6
7
"fmt"
7
8
"io"
8
9
"net"
@@ -20,17 +21,20 @@ import (
20
21
"golang.org/x/sync/errgroup"
21
22
)
22
23
24
+ func runCmd (cmd * exec.Cmd , logs map [string ]* bytes.Buffer ) error {
25
+ if logs != nil {
26
+ setCmdLogs (cmd , logs )
27
+ }
28
+ fmt .Fprintf (cmd .Stderr , "> runCmd %v %+v\n " , time .Now (), cmd .String ())
29
+ return cmd .Run ()
30
+ }
31
+
23
32
func startCmd (cmd * exec.Cmd , logs map [string ]* bytes.Buffer ) (func () error , error ) {
24
33
if logs != nil {
25
- b := new (bytes.Buffer )
26
- logs ["stdout: " + cmd .Path ] = b
27
- cmd .Stdout = & lockingWriter {Writer : b }
28
- b = new (bytes.Buffer )
29
- logs ["stderr: " + cmd .Path ] = b
30
- cmd .Stderr = & lockingWriter {Writer : b }
34
+ setCmdLogs (cmd , logs )
31
35
}
32
36
33
- fmt .Fprintf (cmd .Stderr , "> startCmd %v %+v\n " , time .Now (), cmd .Args )
37
+ fmt .Fprintf (cmd .Stderr , "> startCmd %v %+v\n " , time .Now (), cmd .String () )
34
38
35
39
if err := cmd .Start (); err != nil {
36
40
return nil , err
@@ -75,6 +79,15 @@ func startCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
75
79
}, nil
76
80
}
77
81
82
+ func setCmdLogs (cmd * exec.Cmd , logs map [string ]* bytes.Buffer ) {
83
+ b := new (bytes.Buffer )
84
+ logs ["stdout: " + cmd .String ()] = b
85
+ cmd .Stdout = & lockingWriter {Writer : b }
86
+ b = new (bytes.Buffer )
87
+ logs ["stderr: " + cmd .String ()] = b
88
+ cmd .Stderr = & lockingWriter {Writer : b }
89
+ }
90
+
78
91
func waitUnix (address string , d time.Duration ) error {
79
92
address = strings .TrimPrefix (address , "unix://" )
80
93
addr , err := net .ResolveUnixAddr ("unix" , address )
@@ -167,3 +180,13 @@ func Tmpdir(t *testing.T, appliers ...fstest.Applier) (string, error) {
167
180
}
168
181
return tmpdir , nil
169
182
}
183
+
184
+ func randomString (n int ) string {
185
+ chars := "abcdefghijklmnopqrstuvwxyz"
186
+ var b = make ([]byte , n )
187
+ _ , _ = rand .Read (b )
188
+ for k , v := range b {
189
+ b [k ] = chars [v % byte (len (chars ))]
190
+ }
191
+ return string (b )
192
+ }
0 commit comments