Skip to content

Commit

Permalink
Tests to cover the ability to expose the same ports
Browse files Browse the repository at this point in the history
This test is added based on a comment I get from reddit about the
ability to reach two containers exposing the same port without any
collision.

Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
  • Loading branch information
Gianluca Arbezzano committed Jul 24, 2018
1 parent 589c694 commit 7c31fed
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,55 @@ import (
"testing"
)

func TestTwoContainersExposingTheSamePort(t *testing.T) {
ctx := context.Background()
nginxA, err := RunContainer(ctx, "nginx", RequestContainer{
ExportedPort: []string{
"80/tpc",
},
})
if err != nil {
t.Error(err)
}
defer nginxA.Terminate(ctx, t)

nginxB, err := RunContainer(ctx, "nginx", RequestContainer{
ExportedPort: []string{
"80/tpc",
},
})
if err != nil {
t.Error(err)
}
defer nginxB.Terminate(ctx, t)

ipA, err := nginxA.GetIPAddress(ctx)
if err != nil {
t.Error(err)
}

ipB, err := nginxA.GetIPAddress(ctx)
if err != nil {
t.Error(err)
}

resp, err := http.Get(fmt.Sprintf("http://%s", ipA))
if err != nil {
t.Error(err)
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected status code %d. Got %d.", http.StatusOK, resp.StatusCode)
}

resp, err = http.Get(fmt.Sprintf("http://%s", ipB))
if err != nil {
t.Error(err)
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected status code %d. Got %d.", http.StatusOK, resp.StatusCode)
}
}

func TestContainerCreation(t *testing.T) {
ctx := context.Background()
nginxC, err := RunContainer(ctx, "nginx", RequestContainer{
Expand Down

0 comments on commit 7c31fed

Please sign in to comment.