/
runner.go
43 lines (35 loc) · 1.06 KB
/
runner.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
package testrunner
import (
"encoding/json"
"os"
"os/exec"
"time"
"code.cloudfoundry.org/bbs/cmd/bbs/config"
"code.cloudfoundry.org/durationjson"
. "github.com/onsi/gomega"
ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2"
)
func New(binPath string, bbsConfig config.BBSConfig) *ginkgomon.Runner {
if bbsConfig.ReportInterval == 0 {
bbsConfig.ReportInterval = durationjson.Duration(time.Minute)
}
f, err := os.CreateTemp("", "bbs.config")
Expect(err).NotTo(HaveOccurred())
err = json.NewEncoder(f).Encode(bbsConfig)
Expect(err).NotTo(HaveOccurred())
return ginkgomon.New(ginkgomon.Config{
Name: "bbs",
Command: exec.Command(binPath, "-config", f.Name()),
StartCheck: "bbs.started",
StartCheckTimeout: 20 * time.Second,
Cleanup: func() {
// do not use Expect otherwise a race condition will happen
os.RemoveAll(f.Name())
},
})
}
func WaitForMigration(binPath string, bbsConfig config.BBSConfig) *ginkgomon.Runner {
runner := New(binPath, bbsConfig)
runner.StartCheck = "finished-migrations"
return runner
}