Skip to content

Commit

Permalink
Merge pull request #211 from flimzy/grammar
Browse files Browse the repository at this point in the history
Grammar and spelling fixes
  • Loading branch information
gianarb authored Jun 12, 2020
2 parents 825f6a2 + f4a32c4 commit b13233d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
18 changes: 10 additions & 8 deletions docs/features/garbage_collector.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Garbage Collector

Usually one test creates at least one container. At the end it means a lot of
Usually, one test creates at least one container. At the end it means a lot of
containers running. We need to have a way to keep the CI servers reliable
removing unused containers.

Expand All @@ -12,12 +12,13 @@ Containers can be unused because:

## Terminate function

As we saw previously there are at least two way to remove unused containers.
First one is to use the `Terminate(context.Conext)` function available when a
As we saw previously there are at least two ways to remove unused containers.
The first one is to use the `Terminate(context.Conext)` function available when a
container is created. You can call it in your test or you use `defer` .

!!!tip
Remember to `defer` as soon as possible so you won't forget. The best time

Remember to `defer` as soon as possible so you won't forget. The best time
is as soon as you call `testcontainers.GenericContainer` but remember to
check for the `err` first.

Expand All @@ -26,17 +27,18 @@ container is created. You can call it in your test or you use `defer` .
[https://github.com/testcontainers/moby-ryuk](ryuk) helps you to remove
containers/networks/volumes by given filter after specified delay.

It is a project developer by TestContainer and it is used across the board for
It is a project developed by TestContainers, and it is used across the board for
Java, Go and any more.

When you run one tests you will see that there is not only the containers your
tests requires running, there is another one called `ryuk`, we refers to it as
When you run one test, you will see that there is not only the containers your
tests requires running, there is another one called `ryuk`. We refer to it as
`Reaper` as well in this library.

Based on container labels it removes resources created from testcontainers that
are running from more than 10 minutes.
are running for more than 10 minutes.

!!!tip

This feature can be disabled when creating a container

In this way even if you do not call Terminate, something will keep your
Expand Down
42 changes: 22 additions & 20 deletions docs/quickstart/gotest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TestContainers plays well with the native `go test` framework.
The ideal use case is for integration or end to end tests. It helps you to spin
up and manage the dependencies life cycle via Docker.

This is way Docker has to be available for this library to work.
Docker has to be available for this library to work.

## 1. Install

Expand Down Expand Up @@ -35,43 +35,44 @@ func TestWithRedis(t *testing.T) {
```

The `testcontainers.ContainerRequest` describes how the Docker container will
look like. As you ca see it recalls to a lot of concepts related to it.
look.

* `Image` is the docker image the container starts from.
* `ExposedPorts` lists the port that has to be exposed from the container
* `ExposedPorts` lists the ports to be exposed from the container
* `WaitingFor` is a field you can use to validate when a container is ready. It
is important to get this set because it helps to know when the container is
ready to reach any traffic. In this case we checks for the logs we know coming
ready to receive any traffic. In this, case we check for the logs we know come
from Redis, telling us that it is ready to accept requests.

When you use `ExposedPorts` you have to image yourself using `docker run -p
<port>`. When you do so dockerd maps the selected `<port>` from inside the
<port>`. When you do so, `dockerd` maps the selected `<port>` from inside the
container to a random one available on your host.

In the previous example we expose `6379` for `tcp` traffic to the outside. This
In the previous example, we expose `6379` for `tcp` traffic to the outside. This
allows Redis to be reachable from your code that runs outside the container but
it also makes parallelization possible because if you add `t.Parallel` to you
test and each of them starts a Redis container all of them will be exposed on a
it also makes parallelization possible because if you add `t.Parallel` to your
tests, and each of them starts a Redis container each of them will be exposed on a
different random port.

`testcontainers.GenericContainer` creates the container. In this example we are
using `Started: true`. It means that the container function will wait for the
container to be up and running. If you set the `Start` value to `false` it won'
start. Leaving to you the decision about when to start it.
container to be up and running. If you set the `Start` value to `false` it won't
start, leaving to you the decision about when to start it.

All the container has to be removed at some point, otherwise they will run until
the host will overloaded. One of the way we have to clean after ourself is
defering the terminated function: `defer redisC.Terminate(ctx)`.
All the containers must be removed at some point, otherwise they will run until
the host is overloaded. One of the ways we have to clean up is by deferring the
terminated function: `defer redisC.Terminate(ctx)`.

!!!tip
Lock at [features/garbage_collector.md] to know the other way we have to
clean after ourself.

Look at [features/garbage_collector.md] to know the another way you have to
clean up.

## 3. Make your code to talk with the container

This is just an example but usually Go applications that relay on redis are
using the [redis-go](https://github.com/go-redis/redis) client. This code gets the endpoint from the container we
just started and it configures the client.
This is just an example, but usually Go applications that relay on Redis are
using the [redis-go](https://github.com/go-redis/redis) client. This code gets
the endpoint from the container we just started, and it configures the client.

```go
endpoint, err := redisC.Endpoint(ctx, "")
Expand All @@ -89,8 +90,9 @@ _ = client
We expose only one port, so the `Endpoint` does not need a second argument set.

!!!tip
if you expose more than one port you an specify the one you need as second
argument

If you expose more than one port you can specify the one you need as a second
argument.

In this case it returns: `localhost:<mappedportfor-6379>`.

Expand Down
6 changes: 3 additions & 3 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"testing"
)

// SkipIfProviderIsNotHealthy is an utility function capable of skipping tests
// if the provider is not healthy, or runnig at all.
// SkipIfProviderIsNotHealthy is a utility function capable of skipping tests
// if the provider is not healthy, or running at all.
// This is a function designed to be used in your test, when Docker is not mandatory for CI/CD.
// In this way tests that depends on testcontainers won't run if the provider is provisioned correctly.
// In this way tests that depend on testcontainers won't run if the provider is provisioned correctly.
func SkipIfProviderIsNotHealthy(t *testing.T) {
ctx := context.Background()
provider, err := ProviderDocker.GetProvider()
Expand Down

0 comments on commit b13233d

Please sign in to comment.