Skip to content

Commit

Permalink
Merge pull request testcontainers#5 from gianarb/test-same-exposed-port
Browse files Browse the repository at this point in the history
Tests to cover the ability to expose the same ports
  • Loading branch information
gianarb authored Jul 25, 2018
2 parents ef61195 + 59c2ec9 commit 507028f
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 507028f

Please sign in to comment.