-
Notifications
You must be signed in to change notification settings - Fork 160
/
run.go
55 lines (43 loc) · 1.1 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
package testutils
import (
"fmt"
"os"
"os/exec"
"time"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega/gexec"
)
func BuildExecutable() error {
return BuildExecutableFor("", "")
}
func BuildExecutableFor(goos, goarch string) error {
const buildScript = "./../bin/build"
if goos != "" {
err := os.Setenv("GOOS", goos)
if err != nil {
return fmt.Errorf("failed to set GOOS=%s", goos)
}
}
if goarch != "" {
err := os.Setenv("GOARCH", goarch)
if err != nil {
return fmt.Errorf("failed to set GOARCH=%s", goarch)
}
}
session, err := RunCommand(buildScript)
if session.ExitCode() != 0 {
return fmt.Errorf("failed to build bosh:\nstdout:\n%s\nstderr:\n%s", session.Out.Contents(), session.Err.Contents())
}
return err
}
func RunCommand(cmd string, args ...string) (*gexec.Session, error) {
return RunComplexCommand(exec.Command(cmd, args...))
}
func RunComplexCommand(cmd *exec.Cmd) (*gexec.Session, error) {
session, err := gexec.Start(cmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
if err != nil {
return nil, err
}
session.Wait(120 * time.Second)
return session, nil
}