mirror of
https://github.com/docker/compose.git
synced 2025-07-25 22:54:54 +02:00
ECS E2E test using multi-container , multi-port publish app and validating cross-container communication
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
24b40e1a8d
commit
7ef99e163a
@ -33,6 +33,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/fileutils"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
"gotest.tools/v3/icmd"
|
"gotest.tools/v3/icmd"
|
||||||
@ -612,7 +614,7 @@ func TestUpUpdate(t *testing.T) {
|
|||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
singlePortVolumesComposefile = "aci_demo_port_volumes.yaml"
|
singlePortVolumesComposefile = "aci_demo_port_volumes.yaml"
|
||||||
multiPortComposefile = "aci_demo_multi_port.yaml"
|
multiPortComposefile = "demo_multi_port.yaml"
|
||||||
)
|
)
|
||||||
c := NewParallelE2eCLI(t, binDir)
|
c := NewParallelE2eCLI(t, binDir)
|
||||||
sID, groupID, location := setupTestResourceGroup(t, c)
|
sID, groupID, location := setupTestResourceGroup(t, c)
|
||||||
@ -627,6 +629,8 @@ func TestUpUpdate(t *testing.T) {
|
|||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
assert.NilError(t, os.RemoveAll(dstDir))
|
assert.NilError(t, os.RemoveAll(dstDir))
|
||||||
})
|
})
|
||||||
|
_, err = fileutils.CopyFile(filepath.Join(filepath.Join("..", "composefiles"), multiPortComposefile), filepath.Join(dstDir, multiPortComposefile))
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
singlePortVolumesComposefile = filepath.Join(dstDir, singlePortVolumesComposefile)
|
singlePortVolumesComposefile = filepath.Join(dstDir, singlePortVolumesComposefile)
|
||||||
overwriteFileStorageAccount(t, singlePortVolumesComposefile, composeAccountName)
|
overwriteFileStorageAccount(t, singlePortVolumesComposefile, composeAccountName)
|
||||||
|
@ -81,22 +81,41 @@ func TestCompose(t *testing.T) {
|
|||||||
c, stack := setupTest(t)
|
c, stack := setupTest(t)
|
||||||
|
|
||||||
t.Run("compose up", func(t *testing.T) {
|
t.Run("compose up", func(t *testing.T) {
|
||||||
c.RunDockerCmd("compose", "up", "--project-name", stack, "-f", "../composefiles/nginx.yaml")
|
c.RunDockerCmd("compose", "up", "--project-name", stack, "-f", "../composefiles/demo_multi_port.yaml")
|
||||||
})
|
})
|
||||||
|
|
||||||
var url string
|
var webURL, wordsURL string
|
||||||
t.Run("compose ps", func(t *testing.T) {
|
t.Run("compose ps", func(t *testing.T) {
|
||||||
res := c.RunDockerCmd("compose", "ps", "--project-name", stack)
|
res := c.RunDockerCmd("compose", "ps", "--project-name", stack)
|
||||||
lines := strings.Split(res.Stdout(), "\n")
|
fmt.Println(strings.TrimSpace(res.Stdout()))
|
||||||
|
lines := strings.Split(strings.TrimSpace(res.Stdout()), "\n")
|
||||||
|
|
||||||
assert.Equal(t, 3, len(lines))
|
assert.Equal(t, 4, len(lines))
|
||||||
fields := strings.Fields(lines[1])
|
|
||||||
assert.Equal(t, 4, len(fields))
|
var dbDisplayed, wordsDisplayed, webDisplayed bool
|
||||||
assert.Check(t, strings.Contains(fields[0], stack))
|
for _, line := range lines {
|
||||||
assert.Equal(t, "nginx", fields[1])
|
fields := strings.Fields(line)
|
||||||
assert.Equal(t, "1/1", fields[2])
|
containerID := fields[0]
|
||||||
assert.Check(t, strings.Contains(fields[3], "->80/http"))
|
serviceName := fields[1]
|
||||||
url = "http://" + strings.Replace(fields[3], "->80/http", "", 1)
|
switch serviceName {
|
||||||
|
case "db":
|
||||||
|
dbDisplayed = true
|
||||||
|
assert.DeepEqual(t, fields, []string{containerID, serviceName, "1/1"})
|
||||||
|
case "words":
|
||||||
|
wordsDisplayed = true
|
||||||
|
assert.Check(t, strings.Contains(fields[3], ":8080->8080/tcp"))
|
||||||
|
wordsURL = "http://" + strings.Replace(fields[3], "->8080/tcp", "", 1) + "/noun"
|
||||||
|
case "web":
|
||||||
|
webDisplayed = true
|
||||||
|
assert.Equal(t, fields[1], "web")
|
||||||
|
assert.Check(t, strings.Contains(fields[3], ":80->80/tcp"))
|
||||||
|
webURL = "http://" + strings.Replace(fields[3], "->80/tcp", "", 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Check(t, dbDisplayed)
|
||||||
|
assert.Check(t, wordsDisplayed)
|
||||||
|
assert.Check(t, webDisplayed)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("compose ls", func(t *testing.T) {
|
t.Run("compose ls", func(t *testing.T) {
|
||||||
@ -110,21 +129,17 @@ func TestCompose(t *testing.T) {
|
|||||||
assert.Equal(t, "Running", fields[1])
|
assert.Equal(t, "Running", fields[1])
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nginx GET", func(t *testing.T) {
|
t.Run("Words GET validating cross service connection", func(t *testing.T) {
|
||||||
checkUp := func(t poll.LogT) poll.Result {
|
out := HTTPGetWithRetry(t, wordsURL, http.StatusOK, 5*time.Second, 180*time.Second)
|
||||||
r, err := http.Get(url)
|
assert.Assert(t, strings.Contains(out, `"word":`))
|
||||||
if err != nil {
|
})
|
||||||
return poll.Continue("Err while getting %s : %v", url, err)
|
|
||||||
} else if r.StatusCode != http.StatusOK {
|
t.Run("web app GET", func(t *testing.T) {
|
||||||
return poll.Continue("status %s while getting %s", r.Status, url)
|
out := HTTPGetWithRetry(t, webURL, http.StatusOK, 3*time.Second, 120*time.Second)
|
||||||
}
|
assert.Assert(t, strings.Contains(out, "Docker Compose demo"))
|
||||||
b, err := ioutil.ReadAll(r.Body)
|
|
||||||
if err == nil && strings.Contains(string(b), "Welcome to nginx!") {
|
out = HTTPGetWithRetry(t, webURL+"/words/noun", http.StatusOK, 2*time.Second, 60*time.Second)
|
||||||
return poll.Success()
|
assert.Assert(t, strings.Contains(out, `"word":`))
|
||||||
}
|
|
||||||
return poll.Error(fmt.Errorf("No nginx welcome page received at %s: \n%s", url, string(b)))
|
|
||||||
}
|
|
||||||
poll.WaitOn(t, checkUp, poll.WithDelay(2*time.Second), poll.WithTimeout(60*time.Second))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("compose down", func(t *testing.T) {
|
t.Run("compose down", func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user