-
Notifications
You must be signed in to change notification settings - Fork 9
/
main_test.go
68 lines (55 loc) · 1.16 KB
/
main_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package e2e
import (
"fmt"
"log"
"os"
"os/exec"
"testing"
"time"
"github.com/go-resty/resty/v2"
)
const (
PublicURL = "http://localhost:3000/api"
PrivateURL = "http://localhost:3001/api"
)
func isOnline() bool {
for _, v := range []string{PublicURL, PrivateURL} {
_, err := resty.New().
SetBaseURL(v).
SetTimeout(100 * time.Millisecond).
R().
Get("/health")
if err != nil {
log.Println("waiting for health", err)
return false
}
}
return true
}
func TestMain(m *testing.M) {
log.Println("running e2e tests")
if _, ok := os.LookupEnv("CI"); !ok {
if err := exec.Command("docker", "compose", "up", "-d", "--build").Run(); err != nil {
log.Fatal(fmt.Errorf("docker-compose up -d: %w", err))
}
defer func() {
if err := exec.Command("docker", "compose", "down", "-v").Run(); err != nil {
log.Fatal(fmt.Errorf("docker-compose down -v: %w", err))
}
log.Println("e2e tests finished")
}()
}
startedAt := time.Now()
for {
if time.Since(startedAt) > 20*time.Second {
log.Println("timeout")
return
}
if isOnline() {
log.Println("e2e tests started")
break
}
time.Sleep(1 * time.Second)
}
m.Run()
}