Skip to content

Commit

Permalink
Point tests to 127.0.0.1, improve build test contaienr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Apr 27, 2018
1 parent de5da58 commit 08c71da
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions client/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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}
Expand Down
45 changes: 36 additions & 9 deletions daemon/inertia/project/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(),
Expand All @@ -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{},
Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -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)
}

0 comments on commit 08c71da

Please sign in to comment.