From 08c71da82ff0b59d74bfc7ad866b8fff2b0717a8 Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Fri, 27 Apr 2018 00:34:56 -0700 Subject: [PATCH] Point tests to 127.0.0.1, improve build test contaienr cleanup --- client/remote_test.go | 4 +-- daemon/inertia/project/build_test.go | 45 ++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/client/remote_test.go b/client/remote_test.go index e70b974a..e5243666 100644 --- a/client/remote_test.go +++ b/client/remote_test.go @@ -24,7 +24,7 @@ func getTestConfig(writer io.Writer) *Config { func getTestRemote() *RemoteVPS { remote := &RemoteVPS{ - IP: "0.0.0.0", + IP: "127.0.0.1", PEM: "../test/keys/id_rsa", User: "root", Daemon: &DaemonConfig{ @@ -96,7 +96,7 @@ func TestBootstrap(t *testing.T) { script, err = ioutil.ReadFile("bootstrap/daemon-up.sh") assert.Nil(t, err) - daemonScript := fmt.Sprintf(string(script), "test", "8081", "0.0.0.0") + daemonScript := fmt.Sprintf(string(script), "test", "8081", "127.0.0.1") var writer bytes.Buffer session := mockSSHRunner{r: remote} diff --git a/daemon/inertia/project/build_test.go b/daemon/inertia/project/build_test.go index 6e040856..c778a4fa 100644 --- a/daemon/inertia/project/build_test.go +++ b/daemon/inertia/project/build_test.go @@ -9,10 +9,34 @@ import ( "time" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/filters" docker "github.com/docker/docker/client" "github.com/stretchr/testify/assert" ) +func cleanupContainers(cli *docker.Client) error { + ctx := context.Background() + containers, err := cli.ContainerList(ctx, types.ContainerListOptions{}) + if err != nil { + return err + } + + // Gracefully take down all containers except the testvps + for _, container := range containers { + if container.Names[0] != "/testvps" { + timeout := 10 * time.Second + err := cli.ContainerStop(ctx, container.ID, &timeout) + if err != nil { + return err + } + } + } + + // Prune images + _, err = cli.ContainersPrune(ctx, filters.Args{}) + return err +} + func TestDockerComposeIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") @@ -31,14 +55,15 @@ func TestDockerComposeIntegration(t *testing.T) { project: testProjectName, buildType: "docker-compose", } - d.Down(cli, os.Stdout) + err = cleanupContainers(cli) + assert.Nil(t, err) // Execute build err = dockerCompose(d, cli, os.Stdout) assert.Nil(t, err) // Arbitrary wait for containers to start - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) containers, err := cli.ContainerList( context.Background(), @@ -58,7 +83,7 @@ func TestDockerComposeIntegration(t *testing.T) { // try again if project no up (workaround for Travis) if !foundP { - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) containers, err = cli.ContainerList( context.Background(), types.ContainerListOptions{}, @@ -74,7 +99,7 @@ func TestDockerComposeIntegration(t *testing.T) { assert.True(t, foundDC, "docker-compose container should be active") assert.True(t, foundP, "project container should be active") - err = d.Down(cli, os.Stdout) + err = cleanupContainers(cli) assert.Nil(t, err) } @@ -96,7 +121,8 @@ func TestDockerBuildIntegration(t *testing.T) { project: testProjectName, buildType: "dockerfile", } - d.Down(cli, os.Stdout) + err = cleanupContainers(cli) + assert.Nil(t, err) // Execute build err = dockerBuild(d, cli, os.Stdout) @@ -118,7 +144,7 @@ func TestDockerBuildIntegration(t *testing.T) { } assert.True(t, foundP, "project container should be active") - err = d.Down(cli, os.Stdout) + err = cleanupContainers(cli) assert.Nil(t, err) } @@ -140,7 +166,8 @@ func TestHerokuishBuildIntegration(t *testing.T) { project: testProjectName, buildType: "herokuish", } - d.Down(cli, os.Stdout) + err = cleanupContainers(cli) + assert.Nil(t, err) // Execute build err = herokuishBuild(d, cli, os.Stdout) @@ -162,6 +189,6 @@ func TestHerokuishBuildIntegration(t *testing.T) { } assert.True(t, foundP, "project container should be active") - // err = d.Down(cli, os.Stdout) - // assert.Nil(t, err) + err = cleanupContainers(cli) + assert.Nil(t, err) }