Skip to content

Commit cd1c542

Browse files
committed
feat(tests): only pull deis/test-etcd if it is missing
1 parent 2507e91 commit cd1c542

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

tests/dockercliutils/dockercliutils.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import (
1919
func DaemonAddr() string {
2020
addr := os.Getenv("TEST_DAEMON_ADDR")
2121
if addr == "" {
22-
addr = "/var/run/docker.sock"
22+
if utils.GetHostOs() == "darwin" {
23+
addr = "172.17.8.100:4243"
24+
} else {
25+
addr = "/var/run/docker.sock"
26+
}
2327
}
2428
return addr
2529
}
@@ -28,7 +32,11 @@ func DaemonAddr() string {
2832
func DaemonProto() string {
2933
proto := os.Getenv("TEST_DAEMON_PROTO")
3034
if proto == "" {
31-
proto = "unix"
35+
if utils.GetHostOs() == "darwin" {
36+
proto = "tcp"
37+
} else {
38+
proto = "unix"
39+
}
3240
}
3341
return proto
3442
}
@@ -85,14 +93,8 @@ func DeisServiceTest(
8593
// GetNewClient returns a new docker test client.
8694
func GetNewClient() (
8795
cli *client.DockerCli, stdout *io.PipeReader, stdoutPipe *io.PipeWriter) {
88-
var testDaemonAddr, testDaemonProto string
89-
if utils.GetHostOs() == "darwin" {
90-
testDaemonAddr = "172.17.8.100:4243"
91-
testDaemonProto = "tcp"
92-
} else {
93-
testDaemonAddr = DaemonAddr()
94-
testDaemonProto = DaemonProto()
95-
}
96+
testDaemonAddr := DaemonAddr()
97+
testDaemonProto := DaemonProto()
9698
stdout, stdoutPipe = io.Pipe()
9799
cli = client.NewDockerCli(
98100
nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
@@ -129,9 +131,9 @@ func BuildImage(t *testing.T, path string, tag string) error {
129131
if err = cli.CmdBuild("--tag="+tag, path); err != nil {
130132
return
131133
}
132-
err = CloseWrap(stdout, stdoutPipe)
134+
err = CloseWrap(stdout, stdoutPipe)
133135
}()
134-
PrintToStdout(t, stdout, stdoutPipe, "build docker file")
136+
PrintToStdout(t, stdout, stdoutPipe, "build docker file")
135137
return err
136138
}
137139

@@ -171,7 +173,7 @@ func PullImage(t *testing.T, cli *client.DockerCli, args ...string) {
171173

172174
// RunContainer runs a docker image with the given arguments.
173175
func RunContainer(cli *client.DockerCli, args ...string) error {
174-
fmt.Println("Running docker container", args[1])
176+
fmt.Println("--- Run docker container", args[1])
175177
err := cli.CmdRun(args...)
176178
if err != nil {
177179
// Ignore certain errors we see in io handling.
@@ -302,14 +304,9 @@ func removeImages(t *testing.T, sliceImageIds []string) {
302304

303305
// ClearTestSession cleans up after a typical test session.
304306
func ClearTestSession(t *testing.T, uid string) {
305-
fmt.Println("clearing test session", uid)
307+
fmt.Println("--- Clear test session", uid)
306308
sliceContainerIds := getContainerIds(t, uid)
307-
// sliceImageids := getImageIds(t, uid)
308-
// //fmt.Println(sliceContainerIds)
309-
// //fmt.Println(sliceImageids)
310-
// fmt.Println("removing containers and images for the test session " + uid)
311309
stopContainers(t, sliceContainerIds)
312-
// removeImages(t, sliceImageids)
313310
}
314311

315312
// GetImageID returns the ID of a docker image.
@@ -333,12 +330,17 @@ func GetImageID(t *testing.T, repo string) string {
333330
func RunEtcdTest(t *testing.T, uid string, port string) {
334331
var err error
335332
cli, stdout, stdoutPipe := GetNewClient()
333+
etcdImage := "deis/test-etcd:latest"
336334
done2 := make(chan bool, 1)
337335
ipaddr := utils.GetHostIPAddress()
338336
go func() {
339-
if err = cli.CmdPull("deis/test-etcd:latest"); err != nil {
340-
CloseWrap(stdout, stdoutPipe)
341-
return
337+
fmt.Printf("--- Check that %s is present\n", etcdImage)
338+
if err = cli.CmdHistory("-q", etcdImage); err != nil {
339+
err = nil
340+
if err = cli.CmdPull(etcdImage); err != nil {
341+
CloseWrap(stdout, stdoutPipe)
342+
return
343+
}
342344
}
343345
// PullImage(t, cli, "deis/test-etcd:latest")
344346
done2 <- true

0 commit comments

Comments
 (0)