Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: remove code snippets from main README #631

Merged
merged 1 commit into from Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 1 addition & 81 deletions README.md
Expand Up @@ -6,85 +6,5 @@ _Testcontainers for Go_ is a Go package that makes it simple to create and clean
automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers
that should be run as part of a test and clean up those resources when the test is done.

Here's an example of a test that spins up an NGINX container validates that it returns 200 for the status code:

```go
package main

import (
"context"
"fmt"
"net/http"
"testing"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)

type nginxContainer struct {
testcontainers.Container
URI string
}

func setupNginx(ctx context.Context) (*nginxContainer, error) {
req := testcontainers.ContainerRequest{
Image: "nginx",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/"),
}
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return nil, err
}

ip, err := container.Host(ctx)
if err != nil {
return nil, err
}

mappedPort, err := container.MappedPort(ctx, "80")
if err != nil {
return nil, err
}

uri := fmt.Sprintf("http://%s:%s", ip, mappedPort.Port())

return &nginxContainer{Container: container, URI: uri}, nil
}

func TestIntegrationNginxLatestReturn(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

ctx := context.Background()

nginxC, err := setupNginx(ctx)
if err != nil {
t.Fatal(err)
}

// Clean up the container after the test is complete
defer func() {
if err := nginxC.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %v", err)
}
}()

resp, err := http.Get(nginxC.URI)
if resp.StatusCode != http.StatusOK {
t.Fatalf("Expected status code %d. Got %d.", http.StatusOK, resp.StatusCode)
}
}
```

Cleaning up your environment after test completion should be accomplished by deferring the container termination, e.g
`defer nginxC.Terminate(ctx)`. Reaper (Ryuk) is also enabled by default to help clean up.

## Documentation

More information about _Testcontainers for Go_ can be found in [./docs](./docs), which is rendered at
You can find more information about _Testcontainers for Go_ in the [./docs](./docs) directory, which is rendered at
[golang.testcontainers.org](https://golang.testcontainers.org).