9
9
10
10
"github.com/docker/docker/api/types"
11
11
"github.com/docker/docker/client"
12
+
13
+ "scroll-tech/common/docker"
12
14
)
13
15
14
16
var (
@@ -35,24 +37,24 @@ type ImgDB struct {
35
37
password string
36
38
37
39
running bool
38
- * Cmd
40
+ * docker. Cmd
39
41
}
40
42
41
43
// NewImgDB return postgres db img instance.
42
- func NewImgDB (t * testing.T , image , password , dbName string , port int ) ImgInstance {
44
+ func NewImgDB (t * testing.T , image , password , dbName string , port int ) docker. ImgInstance {
43
45
return & ImgDB {
44
46
image : image ,
45
47
name : fmt .Sprintf ("%s-%s_%d" , image , dbName , port ),
46
48
password : password ,
47
49
dbName : dbName ,
48
50
port : port ,
49
- Cmd : NewCmd (t ),
51
+ Cmd : docker . NewCmd (t ),
50
52
}
51
53
}
52
54
53
55
// Start postgres db container.
54
56
func (i * ImgDB ) Start () error {
55
- id := getContainerID (i .name )
57
+ id := docker . GetContainerID (i .name )
56
58
if id != "" {
57
59
return fmt .Errorf ("container already exist, name: %s" , i .name )
58
60
}
@@ -74,7 +76,7 @@ func (i *ImgDB) Stop() error {
74
76
75
77
ctx := context .Background ()
76
78
// check if container is running, stop the running container.
77
- id := getContainerID (i .name )
79
+ id := docker . GetContainerID (i .name )
78
80
if id != "" {
79
81
timeout := time .Second * 3
80
82
if err := cli .ContainerStop (ctx , id , & timeout ); err != nil {
@@ -122,7 +124,7 @@ func (i *ImgDB) isOk() bool {
122
124
select {
123
125
case <- okCh :
124
126
time .Sleep (time .Millisecond * 1500 )
125
- i .id = getContainerID (i .name )
127
+ i .id = docker . GetContainerID (i .name )
126
128
return i .id != ""
127
129
case <- time .NewTimer (time .Second * 10 ).C :
128
130
return false
0 commit comments