-
Notifications
You must be signed in to change notification settings - Fork 18
/
tarantool_dockertest.go
56 lines (50 loc) · 1.23 KB
/
tarantool_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
package Tt
import (
"context"
"time"
"github.com/kokizzu/gotro/D"
"github.com/ory/dockertest/v3"
"github.com/tarantool/go-tarantool/v2"
)
type TtDockerTest struct {
User string
Password string
Image string
Port string
pool *D.DockerTest
}
// ImageVersion https://hub.docker.com/r/tarantool/tarantool
/*
tarantoolctl connect 3301
*/
func (in *TtDockerTest) ImageVersion(pool *D.DockerTest, version string) *dockertest.RunOptions {
in.pool = pool
in.SetDefaults(version)
return &dockertest.RunOptions{
Repository: `tarantool/tarantool`,
Name: `dockertest-tarantool-` + pool.Uniq,
Tag: in.Image,
NetworkID: pool.Network.ID,
Env: []string{
`TARANTOOL_USER_NAME=` + in.User,
`TARANTOOL_USER_PASSWORD=` + in.Password,
},
}
}
func (in *TtDockerTest) SetDefaults(img string) {
if in.Image == `` {
in.Image = img
}
}
func (in *TtDockerTest) ConnectCheck(res *dockertest.Resource) (taran *tarantool.Connection, err error) {
in.Port = res.GetPort("3301/tcp")
hostPort := in.pool.HostPort(in.Port)
taran, err = tarantool.Connect(context.Background(), tarantool.NetDialer{
Address: hostPort,
User: in.User,
Password: in.Password,
}, tarantool.Opts{
Timeout: 8 * time.Second,
})
return
}