Skip to content

Commit

Permalink
Merge pull request #51 from bmuschko/handle-returned-errors
Browse files Browse the repository at this point in the history
Handle returned errors
  • Loading branch information
gianarb authored Feb 7, 2019
2 parents 47c0da6 + 0e87eb3 commit 46f81ab
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 17 deletions.
74 changes: 65 additions & 9 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ func TestTwoContainersExposingTheSamePort(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxA.Terminate(ctx)
defer func() {
err := nginxA.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

nginxB, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
Expand All @@ -39,7 +44,12 @@ func TestTwoContainersExposingTheSamePort(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxB.Terminate(ctx)
defer func() {
err := nginxB.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

ipA, err := nginxA.Host(ctx)
if err != nil {
Expand Down Expand Up @@ -91,7 +101,12 @@ func TestContainerCreation(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()
ip, err := nginxC.Host(ctx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -128,7 +143,12 @@ func TestContainerCreationAndWaitForListeningPortLongEnough(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()
origin, err := nginxC.PortEndpoint(ctx, nat.Port(nginxPort), "http")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -158,7 +178,10 @@ func TestContainerCreationTimesOut(t *testing.T) {
})
if err == nil {
t.Error("Expected timeout")
nginxC.Terminate(ctx)
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}
}

Expand All @@ -178,9 +201,20 @@ func TestContainerRespondsWithHttp200ForIndex(t *testing.T) {
},
Started: true,
})
defer nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

origin, err := nginxC.PortEndpoint(ctx, nat.Port(nginxPort), "http")
if err != nil {
t.Fatal(err)
}
resp, err := http.Get(origin)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -208,17 +242,34 @@ func TestContainerRespondsWithHttp404ForNonExistingPage(t *testing.T) {
},
Started: true,
})
RunContainer(ctx, "nginx", RequestContainer{
if err != nil {
t.Fatal(err)
}
rC, err := RunContainer(ctx, "nginx", RequestContainer{
ExportedPort: []string{
nginxPort,
},
WaitingFor: wait.ForHTTP("/nonExistingPage").WithStatusCodeMatcher(func(status int) bool {
return status == http.StatusNotFound
}),
})
defer nginxC.Terminate(ctx)
if rC != nil {
t.Fatal(rC)
}
if err != nil {
t.Fatal(err)
}
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

origin, err := nginxC.PortEndpoint(ctx, nat.Port(nginxPort), "http")
if err != nil {
t.Fatal(err)
}
resp, err := http.Get(origin + "/nonExistingPage")
if err != nil {
t.Error(err)
Expand All @@ -242,7 +293,12 @@ func TestContainerCreationTimesOutWithHttp(t *testing.T) {
},
Started: true,
})
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

if err == nil {
t.Error("Expected timeout")
Expand Down
58 changes: 50 additions & 8 deletions legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ func TestLegacyTwoContainersExposingTheSamePort(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxA.Terminate(ctx)
defer func() {
err := nginxA.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

nginxB, err := RunContainer(ctx, "nginx", RequestContainer{
ExportedPort: []string{
Expand All @@ -31,7 +36,12 @@ func TestLegacyTwoContainersExposingTheSamePort(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxB.Terminate(ctx)
defer func() {
err := nginxB.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

ipA, portA, err := nginxA.GetHostEndpoint(ctx, "80/tcp")
if err != nil {
Expand Down Expand Up @@ -72,7 +82,12 @@ func TestLegacyContainerCreation(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()
ip, port, err := nginxC.GetHostEndpoint(ctx, nginxPort)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -101,7 +116,12 @@ func TestLegacyContainerCreationAndWaitForListeningPortLongEnough(t *testing.T)
if err != nil {
t.Fatal(err)
}
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()
ip, port, err := nginxC.GetHostEndpoint(ctx, nginxPort)
if err != nil {
t.Fatal(err)
Expand All @@ -127,7 +147,10 @@ func TestLegacyContainerCreationTimesOut(t *testing.T) {
})
if err == nil {
t.Error("Expected timeout")
nginxC.Terminate(ctx)
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}
}

Expand All @@ -145,9 +168,17 @@ func TestLegacyContainerRespondsWithHttp200ForIndex(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

ip, port, err := nginxC.GetHostEndpoint(ctx, nginxPort)
if err != nil {
t.Fatal(err)
}
resp, err := http.Get(fmt.Sprintf("http://%s:%s", ip, port))
if err != nil {
t.Error(err)
Expand All @@ -173,9 +204,17 @@ func TestLegacyContainerRespondsWithHttp404ForNonExistingPage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nginxC.Terminate(ctx)
defer func() {
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
}()

ip, port, err := nginxC.GetHostEndpoint(ctx, nginxPort)
if err != nil {
t.Fatal(err)
}
resp, err := http.Get(fmt.Sprintf("http://%s:%s/nonExistingPage", ip, port))
if err != nil {
t.Error(err)
Expand All @@ -196,7 +235,10 @@ func TestLegacyContainerCreationTimesOutWithHttp(t *testing.T) {
})

if err == nil {
nginxC.Terminate(ctx)
err := nginxC.Terminate(ctx)
if err != nil {
t.Fatal(err)
}
t.Error("Expected timeout")
}
}

0 comments on commit 46f81ab

Please sign in to comment.