-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.go
45 lines (35 loc) · 938 Bytes
/
docker.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 testinfra
import (
"fmt"
"time"
"gopkg.in/ory-am/dockertest.v3"
)
var pool *dockertest.Pool
type checkFunc func() error
func init() {
var err error
pool, err = dockertest.NewPool("")
if err != nil {
panic(err)
}
}
func StartContainer(image, tag string, env []string) (*dockertest.Resource, error) {
resource, err := pool.Run(image, tag, env)
if err != nil {
return nil, err
}
return resource, nil
}
func waitContainer(f checkFunc) error {
pool.MaxWait = 30 * time.Second
return pool.Retry(f)
}
func GetIP(resource *dockertest.Resource, publishedPort string) string {
return resource.GetBoundIP(publishedPort)
}
func GetPort(resource *dockertest.Resource, publishedPort string) string {
return resource.GetPort(publishedPort)
}
func GetIPPort(resource *dockertest.Resource, publishedPort string) string {
return fmt.Sprintf("%s:%s", GetIP(resource, publishedPort), GetPort(resource, publishedPort))
}