-
Notifications
You must be signed in to change notification settings - Fork 18
/
meilisearch_dockertest.go
55 lines (47 loc) · 1.2 KB
/
meilisearch_dockertest.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 Ms
import (
"net"
"time"
"github.com/ory/dockertest/v3"
"github.com/kokizzu/gotro/D"
)
type MsDockerTest struct {
MasterKey string
Image string
pool *D.DockerTest
Port string
}
// https://hub.docker.com/r/getmeili/meilisearch
func (in *MsDockerTest) ImageVersion(pool *D.DockerTest, version string) *dockertest.RunOptions {
in.pool = pool
in.SetDefaults(version)
return &dockertest.RunOptions{
Repository: `getmeili/meilisearch`,
Name: `dockertest-meili-` + pool.Uniq,
Tag: in.Image,
NetworkID: pool.Network.ID,
Env: []string{},
Cmd: []string{`--master-key=` + in.MasterKey},
}
}
func (in *MsDockerTest) ImageLatest(pool *D.DockerTest) *dockertest.RunOptions {
return in.ImageVersion(pool, `latest`)
}
func (in *MsDockerTest) SetDefaults(img string) {
if in.Image == `` {
in.Image = img
}
}
func (in *MsDockerTest) ConnectCheck(res *dockertest.Resource) (err error) {
in.Port = res.GetPort("7700/tcp")
hostPort := in.pool.HostPort(in.Port)
// using net Dial instead of proper driver
var conn net.Conn
conn, err = net.DialTimeout("tcp", hostPort, 1*time.Second)
if conn != nil {
defer func() {
_ = conn.Close()
}()
}
return
}