-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport_test.go
45 lines (38 loc) · 960 Bytes
/
support_test.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
package gracefully_test
import (
"context"
"fmt"
"os"
"os/exec"
"strings"
"time"
)
var (
simpleServerGo = "./testdata/simple_server/main.go"
simpleServerBin = "./testdata/simple_server/main"
afterShutdownServerGo = "./testdata/after_shutdown/main.go"
afterShutdownServerBin = "./testdata/after_shutdown/main"
afterShutdownFile = "./testdata/after_shutdown/after_shutdown.txt"
)
func setup() {
cleanup()
must(goCompile(simpleServerGo))
must(goCompile(afterShutdownServerGo))
}
func cleanup() {
os.Remove(simpleServerBin)
os.Remove(afterShutdownServerBin)
os.Remove(afterShutdownFile)
}
func goCompile(f string) error {
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
cmd := exec.CommandContext(c, "go", "build", "-o", strings.TrimSuffix(f, ".go"), f)
fmt.Printf("GOTTEN CMD :: %s", cmd.String())
return cmd.Run()
}
func must(err error) {
if err != nil {
panic(err)
}
}