-
Notifications
You must be signed in to change notification settings - Fork 17
/
mariadb_dockertest.go
60 lines (52 loc) · 1.26 KB
/
mariadb_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
56
57
58
59
60
package Ma
import (
"net"
"time"
"github.com/ory/dockertest/v3"
"github.com/kokizzu/gotro/D"
)
type MaDockerTest struct {
Password string
Image string
pool *D.DockerTest
Port string
}
// https://hub.docker.com/_/mariadb
/*
docker-compose exec --user root mariadb1 /bin/bash
docker-compose exec --user root mariadb1 mysql -u root -p
*/
func (in *MaDockerTest) ImageVersion(pool *D.DockerTest, version string) *dockertest.RunOptions {
in.pool = pool
in.SetDefaults(version)
return &dockertest.RunOptions{
Repository: `mariadb`,
Name: `dockertest-mariadb-` + pool.Uniq,
Tag: in.Image,
NetworkID: pool.Network.ID,
Env: []string{
`MYSQL_ROOT_PASSWORD=` + in.Password,
},
}
}
func (in *MaDockerTest) ImageLatest(pool *D.DockerTest) *dockertest.RunOptions {
return in.ImageVersion(pool, `latest`)
}
func (in *MaDockerTest) SetDefaults(img string) {
if in.Image == `` {
in.Image = img
}
}
func (in *MaDockerTest) ConnectCheck(res *dockertest.Resource) (err error) {
in.Port = res.GetPort("3306/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
}