-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.go
63 lines (49 loc) · 1.21 KB
/
run.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
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"fmt"
"io"
"log"
"os/exec"
"strings"
"sync"
)
func pipeStd(steamCreator func() (io.ReadCloser, error), print func(line string)) io.ReadCloser {
stream, err := steamCreator()
if err != nil {
log.Fatal(err)
}
go func() {
reader := bufio.NewScanner(stream)
for reader.Scan() {
print(reader.Text())
}
}()
return stream
}
func runInGoroutine(waitGroup *sync.WaitGroup, label, executable string, args ...string) {
fmt.Printf("%s Starting %s %s\n", label, executable, strings.Join(args, " "))
defer waitGroup.Done()
cmd := exec.Command(executable, args...)
print := func(line string) {
fmt.Printf("%s %s\n", label, line)
}
stdout := pipeStd(cmd.StdoutPipe, print)
stderr := pipeStd(cmd.StderrPipe, print)
defer stdout.Close()
defer stderr.Close()
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
if err := cmd.Wait(); err != nil {
log.Fatal(err)
}
}
func main() {
var wg sync.WaitGroup
wg.Add(3)
go runInGoroutine(&wg, "[eventhub]", "go", "run", "tests/e2e/go/eventhub/main.go")
go runInGoroutine(&wg, "[device] ", "go", "run", "tests/e2e/go/device/main.go")
go runInGoroutine(&wg, "[app] ", "go", "run", "tests/e2e/go/app/main.go")
wg.Wait()
}