Skip to content

Commit

Permalink
Merge pull request #81 from testcontainers/feature/remove-legacy
Browse files Browse the repository at this point in the history
BC break - Remove legacy lib in Sept
  • Loading branch information
gianarb authored Sep 2, 2019
2 parents 1637080 + 35a19b7 commit a059006
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 428 deletions.
46 changes: 0 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,49 +61,3 @@ can use it to make a GET: `resp, err := http.Get(fmt.Sprintf("http://%s", ip))`
To clean your environment you can defer the container termination `defer
nginxC.Terminate(ctx, t)`. `t` is `*testing.T` and it is used to notify is the
`defer` failed marking the test as failed.

You can build more complex flow using env var to configure the containers. Let's
suppose you are testing an application that requires redis:

```go
func TestRedisPing(t *testing.T) {
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "redis",
ExposedPorts: []string{"6379/tcp"},
}
redisC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
t.Error(err)
}
defer redisC.Terminate(ctx)
ip, err := redisC.Host(ctx)
if err != nil {
t.Error(err)
}
redisPort, err := redisC.MappedPort(ctx, "6479/tcp")
if err != nil {
t.Error(err)
}

appReq := testcontainers.ContainerRequest{
ExposedPorts: []string{"8081/tcp"},
Env: map[string]string{
"REDIS_HOST": fmt.Sprintf("http://%s:%s", ip, redisPort.Port()),
},
}
appC, err := testcontainers.RunContainer(ctx, "your/app", testcontainers.GenericContainerRequest{
ContainerRequest: appReq,
Started: true,
})
if err != nil {
t.Error(err)
}
defer appC.Terminate(ctx)

// your assertions
}
```
55 changes: 0 additions & 55 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,61 +446,6 @@ func TestContainerRespondsWithHttp200ForIndex(t *testing.T) {
}
}

func TestContainerRespondsWithHttp404ForNonExistingPage(t *testing.T) {
t.Skip("Wait needs to be fixed")
ctx := context.Background()

nginxPort := "80/tcp"
// delayed-nginx will wait 2s before opening port
nginxC, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
Image: "nginx",
ExposedPorts: []string{
nginxPort,
},
WaitingFor: wait.ForHTTP("/nonExistingPage").WithStatusCodeMatcher(func(status int) bool {
return status == http.StatusNotFound
}),
},
Started: true,
})
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
}),
})
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)
}
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Expected status code %d. Got %d.", http.StatusNotFound, resp.StatusCode)
}
}

func TestContainerCreationTimesOutWithHttp(t *testing.T) {
t.Skip("Wait needs to be fixed")
ctx := context.Background()
Expand Down
83 changes: 0 additions & 83 deletions legacy.go

This file was deleted.

Loading

0 comments on commit a059006

Please sign in to comment.