-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
89 lines (75 loc) · 2.1 KB
/
Copy pathmain_test.go
File metadata and controls
89 lines (75 loc) · 2.1 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"net/http"
"os"
"strconv"
"testing"
"time"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
log "github.com/sirupsen/logrus"
)
var S3Port int
func TestMain(m *testing.M) {
// uses a sensible default on windows (tcp/http) and linux/osx (socket)
pool, err := dockertest.NewPool("")
if err != nil {
log.Fatalf("Could not construct pool: %s", err)
}
// uses pool to try to connect to Docker
err = pool.Client.Ping()
if err != nil {
log.Fatalf("Could not connect to Docker: %s", err)
}
minio, err := pool.RunWithOptions(&dockertest.RunOptions{
Name: "s3",
Repository: "minio/minio",
Tag: "RELEASE.2023-05-18T00-05-36Z",
Cmd: []string{"server", "/data", "--console-address", ":9001"},
Env: []string{
"MINIO_ROOT_USER=access",
"MINIO_ROOT_PASSWORD=secretKey",
"MINIO_SERVER_URL=http://127.0.0.1:9000",
},
}, func(config *docker.HostConfig) {
// set AutoRemove to true so that stopped container goes away by itself
config.AutoRemove = true
config.RestartPolicy = docker.RestartPolicy{
Name: "no",
}
})
if err != nil {
log.Panicf("Could not start resource: %s", err)
}
s3HostAndPort := minio.GetHostPort("9000/tcp")
S3Port, _ = strconv.Atoi(minio.GetPort("9000/tcp"))
client := http.Client{Timeout: 5 * time.Second}
req, err := http.NewRequest(http.MethodGet, "http://"+s3HostAndPort+"/minio/health/live", http.NoBody)
if err != nil {
log.Panic(err)
}
// exponential backoff-retry, because the application in the container might not be ready to accept connections yet
if err := pool.Retry(func() error {
res, err := client.Do(req)
if err != nil {
return err
}
err = res.Body.Close()
if err != nil {
return err
}
return nil
}); err != nil {
if err := pool.Purge(minio); err != nil {
log.Panicf("Could not purge oidc resource: %s", err)
}
log.Panicf("Could not connect to oidc: %s", err)
}
log.Println("starting tests")
code := m.Run()
log.Println("tests completed")
if err := pool.Purge(minio); err != nil {
log.Fatalf("Could not purge resource: %s", err)
}
os.Exit(code)
}