Skip to content

Commit

Permalink
Merge branch 'main' into dev-tools
Browse files Browse the repository at this point in the history
* main:
  chore: replace 'assert' with 'require' (#2827)
  chore: replace 'assert' with 'require' for critical checks (#2824)
  chore: bump ryuk to latest release (#2818)
  feat: add require for critical checks (#2812)
  chore(deps): bump release-drafter/release-drafter from 5.25.0 to 6.0.0 (#2805)
  feat: add etcd module (#2788)
  feat: add dynamodb-local module (#2799)
  fix(redpanda): wait for (#2794)
  fix(elasticsearch): wait for (#2724)
  chore: update dockercfg module (#2801)
  • Loading branch information
mdelapenya committed Oct 17, 2024
2 parents 412d57b + fb6a4ba commit 307e501
Show file tree
Hide file tree
Showing 140 changed files with 2,288 additions and 318 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
go-version: [1.22.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, azurite, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, databend, dolt, elasticsearch, gcloud, grafana-lgtm, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, valkey, vault, vearch, weaviate]
module: [artemis, azurite, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, databend, dolt, dynamodb, elasticsearch, etcd, gcloud, grafana-lgtm, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, valkey, vault, vearch, weaviate]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
pull-requests: write # for release-drafter/release-drafter to add label to PR
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@09c613e259eb8d4e7c81c2cb00618eb5fc4575a7 # v5.19.0
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348 # v5.19.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@
"name": "module / dolt",
"path": "../modules/dolt"
},
{
"name": "module / dynamodb",
"path": "../modules/dynamodb"
},
{
"name": "module / elasticsearch",
"path": "../modules/elasticsearch"
},
{
"name": "module / etcd",
"path": "../modules/etcd"
},
{
"name": "module / gcloud",
"path": "../modules/gcloud"
Expand Down
10 changes: 7 additions & 3 deletions cmd/devtools/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ func TestModule_Validate(outer *testing.T) {

for _, test := range tests {
outer.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.expectedErr, test.module.Validate())
if test.expectedErr != nil {
require.EqualError(t, test.module.Validate(), test.expectedErr.Error())
} else {
require.NoError(t, test.module.Validate())
}
})
}
}
Expand Down Expand Up @@ -277,7 +281,7 @@ func TestGenerate(t *testing.T) {

moduleDirFileInfo, err := os.Stat(moduleDirPath)
require.NoError(t, err) // error nil implies the file exist
assert.True(t, moduleDirFileInfo.IsDir())
require.True(t, moduleDirFileInfo.IsDir())

moduleDocFile := filepath.Join(examplesDocTmp, moduleNameLower+".md")
_, err = os.Stat(moduleDocFile)
Expand Down Expand Up @@ -333,7 +337,7 @@ func TestGenerateModule(t *testing.T) {

moduleDirFileInfo, err := os.Stat(moduleDirPath)
require.NoError(t, err) // error nil implies the file exist
assert.True(t, moduleDirFileInfo.IsDir())
require.True(t, moduleDirFileInfo.IsDir())

moduleDocFile := filepath.Join(modulesDocTmp, moduleNameLower+".md")
_, err = os.Stat(moduleDocFile)
Expand Down
12 changes: 6 additions & 6 deletions cmd/devtools/mkdocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestReadMkDocsConfig(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, config)

assert.Equal(t, "Testcontainers for Go", config.SiteName)
assert.Equal(t, "https://github.com/testcontainers/testcontainers-go", config.RepoURL)
assert.Equal(t, "edit/main/docs/", config.EditURI)
require.Equal(t, "Testcontainers for Go", config.SiteName)
require.Equal(t, "https://github.com/testcontainers/testcontainers-go", config.RepoURL)
require.Equal(t, "edit/main/docs/", config.EditURI)

// theme
theme := config.Theme
Expand All @@ -51,9 +51,9 @@ func TestReadMkDocsConfig(t *testing.T) {
// nav bar
nav := config.Nav
assert.Equal(t, "index.md", nav[0].Home)
assert.NotEmpty(t, nav[2].Features)
assert.NotEmpty(t, nav[3].Modules)
assert.NotEmpty(t, nav[4].Examples)
require.NotEmpty(t, nav[2].Features)
require.NotEmpty(t, nav[3].Modules)
require.NotEmpty(t, nav[4].Examples)
}

func TestNavItems(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion container_ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParseDockerIgnore(t *testing.T) {
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestParseDockerIgnore(t *testing.T) {
for _, testCase := range testCases {
exists, excluded, err := parseDockerIgnore(testCase.filePath)
assert.Equal(t, testCase.exists, exists)
assert.Equal(t, testCase.expectedErr, err)
require.ErrorIs(t, testCase.expectedErr, err)
assert.Equal(t, testCase.expectedExcluded, excluded)
}
}
2 changes: 1 addition & 1 deletion container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func TestCustomLabelsImage(t *testing.T) {
ctr, err := testcontainers.GenericContainer(ctx, req)

require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, ctr.Terminate(ctx)) })
t.Cleanup(func() { require.NoError(t, ctr.Terminate(ctx)) })

ctrJSON, err := ctr.Inspect(ctx)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestContainerStateAfterTermination(t *testing.T) {
state, err := nginx.State(ctx)
require.Error(t, err, "expected error from container inspect.")

assert.Nil(t, state, "expected nil container inspect.")
require.Nil(t, state, "expected nil container inspect.")
})

t.Run("Nil State after termination if raw as already set", func(t *testing.T) {
Expand Down Expand Up @@ -1339,7 +1339,7 @@ func TestContainerInspect_RawInspectIsCleanedOnStop(t *testing.T) {
inspect, err := ctr.Inspect(context.Background())
require.NoError(t, err)

assert.NotEmpty(t, inspect.ID)
require.NotEmpty(t, inspect.ID)

require.NoError(t, ctr.Stop(context.Background(), nil))
}
Expand Down Expand Up @@ -1698,7 +1698,7 @@ func TestDockerContainerCopyEmptyFileFromContainer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Empty(t, fileContentFromContainer)
require.Empty(t, fileContentFromContainer)
}

func TestDockerContainerResources(t *testing.T) {
Expand Down
77 changes: 77 additions & 0 deletions docs/modules/dynamodb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# DynamoDB

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for DynamoDB.

## Adding this module to your project dependencies

Please run the following command to add the DynamoDB module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/dynamodb
```

## Usage example

<!--codeinclude-->
[Creating a DynamoDB container](../../modules/dynamodb/examples_test.go) inside_block:runDynamoDBContainer
<!--/codeinclude-->

## Module Reference

### Run function

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

The DynamoDB module exposes one entrypoint function to create the DynamoDB container, and this function receives three parameters:

```golang
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DynamoDBContainer, error)
```

- `context.Context`, the Go context.
- `string`, the Docker image to use.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the DynamoDB container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different DynamoDB Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "amazon/dynamodb-local:2.2.1")`.

{% include "../features/common_functional_options.md" %}

#### WithSharedDB

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

The `WithSharedDB` option tells the DynamoDB container to use a single database file. At the same time, it marks the container as reusable, which causes that successive calls to the `Run` function will return the same container instance, and therefore, the same database file.

#### WithDisableTelemetry

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

You can turn off telemetry when starting the DynamoDB container, using the option `WithDisableTelemetry`.

### Container Methods

The DynamoDB container exposes the following methods:

#### ConnectionString

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

The `ConnectionString` method returns the connection string to the DynamoDB container. This connection string can be used to connect to the DynamoDB container from your application,
using the AWS SDK or any other DynamoDB client of your choice.

<!--codeinclude-->
[Creating a client](../../modules/dynamodb/dynamodb_test.go) inside_block:createClient
<!--/codeinclude-->

The above example uses `github.com/aws/aws-sdk-go-v2/service/dynamodb` to create a client and connect to the DynamoDB container.
95 changes: 95 additions & 0 deletions docs/modules/etcd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# etcd

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for etcd.

## Adding this module to your project dependencies

Please run the following command to add the etcd module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/etcd
```

## Usage example

<!--codeinclude-->
[Creating a etcd container](../../modules/etcd/examples_test.go) inside_block:runetcdContainer
<!--/codeinclude-->

## Module Reference

### Run function

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

The etcd module exposes one entrypoint function to create the etcd container, and this function receives three parameters:

```golang
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*etcdContainer, error)
```

- `context.Context`, the Go context.
- `string`, the Docker image to use.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the etcd container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different etcd Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "bitnami/etcd:latest")`.

{% include "../features/common_functional_options.md" %}

#### WithAdditionalArgs

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

You can pass additional arguments to the etcd container by using the `WithAdditionalArgs` option. The arguments are passed to the CMD of the etcd container.

#### WithDataDir

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

You can set the data directory for the etcd container by using the `WithDataDir` boolean option. The data directory where the etcd data is stored is `/data.etcd`.

#### WithNodes

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

You can set the number of nodes for the etcd cluster by using the `WithNodes` option, passing the node names for each of the nodes. Single-node clusters are not allowed,
for that reason the functional option receives three string arguments: the first node, the second node, and a variadic argument for the rest of the nodes.
The module starts a container for each node, having the first node a reference to the other nodes. E.g. `WithNodes("etcd-1", "etcd-2")`, `WithNodes("etcd-1", "etcd-2", "etcd-3")` and so on.

The module creates a Docker network for the etcd cluster, and the nodes are connected to this network, so that they can communicate with each other through the network.

#### WithClusterToken

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

Sets the cluster token for the etcd cluster. The cluster token is used to identify the etcd cluster. The default value is `mys3cr3ttok3n`.
The etcd container holds a reference to the cluster token, so you can use it with e.g. `ctr.ClusterToken`.

### Container Methods

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

The etcd container exposes the following methods:

#### ClientEndpoint

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

Returns the client endpoint for the etcd container and an error, if any. In the case of a cluster, it returns the client endpoint for the first node.

#### PeerEndpoint

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

Returns the peer endpoint for the etcd container and an error, if any. In the case of a cluster, it returns the peer endpoint for the first node.
2 changes: 1 addition & 1 deletion examples/nginx/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/nginx/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA=
github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
Expand Down
2 changes: 1 addition & 1 deletion examples/toxiproxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/toxiproxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA=
github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
Expand Down
7 changes: 3 additions & 4 deletions from_dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -38,7 +37,7 @@ func TestBuildImageFromDockerfile(t *testing.T) {
// }
})
require.NoError(t, err)
assert.Equal(t, "test-repo:test-tag", tag)
require.Equal(t, "test-repo:test-tag", tag)

_, _, err = cli.ImageInspectWithRaw(ctx, tag)
require.NoError(t, err)
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestBuildImageFromDockerfile_NoRepo(t *testing.T) {
},
})
require.NoError(t, err)
assert.True(t, strings.HasPrefix(tag, "test-repo:"))
require.True(t, strings.HasPrefix(tag, "test-repo:"))

_, _, err = cli.ImageInspectWithRaw(ctx, tag)
require.NoError(t, err)
Expand Down Expand Up @@ -130,7 +129,7 @@ func TestBuildImageFromDockerfile_NoTag(t *testing.T) {
},
})
require.NoError(t, err)
assert.True(t, strings.HasSuffix(tag, ":test-tag"))
require.True(t, strings.HasSuffix(tag, ":test-tag"))

_, _, err = cli.ImageInspectWithRaw(ctx, tag)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 307e501

Please sign in to comment.