This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ginkgomon.go
77 lines (61 loc) · 1.45 KB
/
ginkgomon.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ginkgomon
import (
"fmt"
"io"
"os"
"os/exec"
"time"
"github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
type Runner struct {
Command *exec.Cmd
Name string
AnsiColorCode string
StartCheck string
StartCheckTimeout time.Duration
Cleanup func()
BufferChan chan *gbytes.Buffer
}
func (r *Runner) Run(sigChan <-chan os.Signal, ready chan<- struct{}) error {
defer ginkgo.GinkgoRecover()
allOutput := gbytes.NewBuffer()
session, err := gexec.Start(
r.Command,
gexec.NewPrefixedWriter(
fmt.Sprintf("\x1b[32m[o]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name),
io.MultiWriter(allOutput, ginkgo.GinkgoWriter),
),
gexec.NewPrefixedWriter(
fmt.Sprintf("\x1b[91m[e]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name),
io.MultiWriter(allOutput, ginkgo.GinkgoWriter),
),
)
Ω(err).ShouldNot(HaveOccurred())
if r.StartCheck != "" {
timeout := r.StartCheckTimeout
if timeout == 0 {
timeout = 5 * time.Second
}
Eventually(allOutput, timeout).Should(gbytes.Say(r.StartCheck))
}
close(ready)
var signal os.Signal
for {
select {
case r.BufferChan <- session.Buffer():
case signal = <-sigChan:
session.Signal(signal)
case <-session.Exited:
if r.Cleanup != nil {
r.Cleanup()
}
if session.ExitCode() == 0 {
return nil
}
return fmt.Errorf("exit status %d", session.ExitCode())
}
}
}