Skip to content

Commit

Permalink
Merge pull request #184 from euanh/test-refactor
Browse files Browse the repository at this point in the history
Refactor duplicated setup and verification code
  • Loading branch information
ehazlett authored Sep 4, 2018
2 parents 2c1eace + 1e45dcd commit f2577d2
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 1,120 deletions.
2 changes: 1 addition & 1 deletion test/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"strings"
"time"

"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
eventtypes "github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/network"
volumetypes "github.com/docker/docker/api/types/volume"
dockerclient "github.com/docker/docker/client"
"github.com/pkg/errors"
"golang.org/x/net/context"
)

var (
Expand Down
4 changes: 4 additions & 0 deletions test/integration/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func NewCommon(manager string, interlockConfigPath string, c *integration.Cluste

// CreateInterlockConfig creates a new Interlock configuration
func (c *Common) CreateInterlockConfig(t *testing.T) {
t.Log("creating interlock service config")
if err := c.testCluster.CopyFile(c.manager, c.interlockConfigPath, "/root/interlock.conf"); err != nil {
t.Fatal(err)
}
Expand All @@ -58,6 +59,7 @@ func (c *Common) CreateInterlockConfig(t *testing.T) {

// CreateInterlockNetwork creates a new Interlock management network
func (c *Common) CreateInterlockNetwork(t *testing.T) {
t.Log("creating interlock network")
if _, _, err := c.testCluster.Exec(c.manager, []string{
"docker",
"network",
Expand All @@ -72,6 +74,7 @@ func (c *Common) CreateInterlockNetwork(t *testing.T) {

// CreateInterlockService creates a new Interlock service
func (c *Common) CreateInterlockService(t *testing.T) {
t.Log("creating interlock service")
interlockServiceID, _, err := c.testCluster.Exec(c.manager, []string{
"docker",
"service",
Expand Down Expand Up @@ -113,6 +116,7 @@ func (c *Common) CreateInterlockService(t *testing.T) {
}

// Wait for proxy to show up.
t.Log("waiting for interlock proxy to start")
if _, err = c.WaitForExec([]string{
"docker",
"service",
Expand Down
83 changes: 11 additions & 72 deletions test/integration/standard/context_root.go
Original file line number Diff line number Diff line change
@@ -1,90 +1,29 @@
package standard

import (
"strings"
"testing"
"time"
)

func testCreateAppServiceContextRoot(t *testing.T) {
appHost := "demo-context-root.test"
contextRoot := "/app"
appServiceID, _, err := testCluster.Exec(manager, []string{
"docker",
"service",
"create",
"-q",
"--label",
"app=demo-test",
"--network",
testNetName,
"--label",
"com.docker.lb.hosts=" + appHost,
"--label",
"com.docker.lb.port=8080",
"--label",
"com.docker.lb.context_root=" + contextRoot,
"--label",
"com.docker.lb.context_root_rewrite=true",
testAppImage,
}, true, nil)
appServiceID, err := createService(
"--label", "app=demo-test",
"--network", testNetName,
"--label", "com.docker.lb.hosts="+appHost,
"--label", "com.docker.lb.port=8080",
"--label", "com.docker.lb.context_root="+contextRoot,
"--label", "com.docker.lb.context_root_rewrite=true",
testAppImage)
if err != nil {
t.Fatal(err)
}
defer testCluster.RemoveService(appServiceID)

status, _, err := testCluster.Exec(manager, []string{
"docker",
"service",
"ls",
"-q",
"-f",
"id=" + appServiceID,
}, true, nil)
resp, err := curl("-sSIL", "http://"+appHost+contextRoot)
if err != nil {
t.Fatal(err)
}
if strings.Index(appServiceID, status) == -1 {
t.Fatal("unable to find app service")
}
defer testCluster.RemoveService(appServiceID)

if status, _, err := testCluster.Exec(manager, []string{
"docker",
"pull",
testCurlImage,
}, true, nil); err != nil {
t.Fatal(status)
}

command := []string{
"docker",
"run",
"--net=host",
"-v",
testHostsFile + ":/etc/hosts",
"--entrypoint",
"curl",
testCurlImage,
"-sSIL",
"--fail",
"http://" + appHost + contextRoot,
}

successChan := make(chan string, 1)
go func() {
for {
resp, err := commonManager.WaitForExec(command, serviceWaitTimeout)
if err != nil {
continue
}

successChan <- resp
}
}()
select {
case resp := <-successChan:
t.Logf("context root routing successful: %s", resp)
case <-time.After(serviceTestTimeout):
t.Fatal("timeout waiting on context root")
}
t.Logf("context root routing successful: %s", resp)
}
75 changes: 8 additions & 67 deletions test/integration/standard/default_backend.go
Original file line number Diff line number Diff line change
@@ -1,84 +1,25 @@
package standard

import (
"strings"
"testing"
"time"
)

func testCreateAppServiceDefaultBackend(t *testing.T) {
netName := "demo-default-backend-net"
createNet(netName, t)
appServiceID, _, err := testCluster.Exec(manager, []string{
"docker",
"service",
"create",
"-q",
"--network",
netName,
"--label",
"com.docker.lb.default_backend=true",
"--label",
"com.docker.lb.port=8080",
testAppImage,
}, true, nil)
appServiceID, err := createService(
"--network", netName,
"--label", "com.docker.lb.default_backend=true",
"--label", "com.docker.lb.port=8080",
testAppImage)
if err != nil {
t.Fatal(err)
}
defer testCluster.RemoveService(appServiceID)

status, _, err := testCluster.Exec(manager, []string{
"docker",
"service",
"ls",
"-q",
"-f",
"id=" + appServiceID,
}, true, nil)
resp, err := curl("-sSIL", "http://anyhost.test")
if err != nil {
t.Fatal(err)
}
if strings.Index(appServiceID, status) == -1 {
t.Fatal("unable to find app service")
}
defer testCluster.RemoveService(appServiceID)

if status, _, err := testCluster.Exec(manager, []string{
"docker",
"pull",
testCurlImage,
}, true, nil); err != nil {
t.Fatal(status)
}

command := []string{
"docker",
"run",
"--net=host",
"-v",
testHostsFile + ":/etc/hosts",
"--entrypoint",
"curl",
testCurlImage,
"-sSIL",
"--fail",
"http://anyhost.test",
}

successChan := make(chan string, 1)
go func() {
for {
resp, err := commonManager.WaitForExec(command, serviceWaitTimeout)
if err != nil {
continue
}

successChan <- resp
}
}()
select {
case resp := <-successChan:
t.Logf("service configured for default backend successfully: %s", resp)
case <-time.After(serviceTestTimeout):
t.Fatal("timeout waiting on default backend")
}
t.Logf("service configured for default backend successfully: %s", resp)
}
Loading

0 comments on commit f2577d2

Please sign in to comment.