Skip to content

Commit

Permalink
Merge branch 'main' into session-ids
Browse files Browse the repository at this point in the history
* main:
  chore: define interfaces for file and project generation (testcontainers#1568)
  chore(deps): bump mkdocs-material from 8.2.7 to 9.2.6 (testcontainers#1567)
  chore(deps): bump the all group in /modules/neo4j with 1 update (testcontainers#1562)
  chore(deps): bump the all group in /modules/clickhouse with 1 update (testcontainers#1563)
  chore(deps): bump the all group in /modules/localstack with 1 update (testcontainers#1564)
  Update actions/github-script to 6.4.1 (testcontainers#1561)
  chore: Update Pipenv to use Python 3.8 (testcontainers#1558)
  feat: convert NATS example into a module (testcontainers#1559)
  chore(deps): bump the all group in /modulegen with 1 update (testcontainers#1554)
  modulegen: use cobra instead of native golang flag (testcontainers#1550)
  • Loading branch information
mdelapenya committed Sep 1, 2023
2 parents b0d7e0d + 69a5d38 commit 3f43bae
Show file tree
Hide file tree
Showing 52 changed files with 1,391 additions and 692 deletions.
22 changes: 11 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ updates:
all:
patterns:
- '*'
- package-ecosystem: gomod
directory: /examples/nats
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
groups:
all:
patterns:
- '*'
- package-ecosystem: gomod
directory: /examples/nginx
schedule:
Expand Down Expand Up @@ -247,6 +236,17 @@ updates:
all:
patterns:
- '*'
- package-ecosystem: gomod
directory: /modules/nats
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
groups:
all:
patterns:
- '*'
- package-ecosystem: gomod
directory: /modules/neo4j
schedule:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
timeout-minutes: 30
steps:
- name: Create pending status
uses: actions/github-script@0.9.0
uses: actions/github-script@6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.repos.createStatus({
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.client_payload.pull_request.head.sha,
Expand Down Expand Up @@ -55,12 +55,12 @@ jobs:
gotestsum --format short-verbose --rerun-fails=5 --packages="./..." --junitfile TEST-unit.xml -- -timeout=30m
- name: Create success status
uses: actions/github-script@0.9.0
uses: actions/github-script@6.4.1
if: success()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.repos.createStatus({
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.client_payload.pull_request.head.sha,
Expand All @@ -70,12 +70,12 @@ jobs:
})
- name: Create failure status
uses: actions/github-script@0.9.0
uses: actions/github-script@6.4.1
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.repos.createStatus({
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.client_payload.pull_request.head.sha,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
matrix:
go-version: [1.20.x, 1.x]
platform: [ubuntu-latest, macos-latest]
module: [artemis, clickhouse, compose, couchbase, k3s, localstack, mariadb, mongodb, mysql, neo4j, postgres, pulsar, redis, redpanda, vault]
module: [artemis, clickhouse, compose, couchbase, k3s, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, redis, redpanda, vault]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand All @@ -111,7 +111,7 @@ jobs:
needs: test-modules
strategy:
matrix:
module: [bigtable, cockroachdb, consul, datastore, firestore, nats, nginx, pubsub, spanner, toxiproxy]
module: [bigtable, cockroachdb, consul, datastore, firestore, nginx, pubsub, spanner, toxiproxy]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: "1.20.x"
Expand Down
8 changes: 4 additions & 4 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"name": "example / firestore",
"path": "../examples/firestore"
},
{
"name": "example / nats",
"path": "../examples/nats"
},
{
"name": "example / nginx",
"path": "../examples/nginx"
Expand Down Expand Up @@ -81,6 +77,10 @@
"name": "module / mysql",
"path": "../modules/mysql"
},
{
"name": "module / nats",
"path": "../modules/nats"
},
{
"name": "module / neo4j",
"path": "../modules/neo4j"
Expand Down
10 changes: 5 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ verify_ssl = true
[dev-packages]

[packages]
mkdocs = "*"
mkdocs-codeinclude-plugin = "*"
mkdocs-material = "*"
mkdocs-markdownextradata-plugin = "*"
mkdocs = "==1.5.2"
mkdocs-codeinclude-plugin = "==0.2.1"
mkdocs-material = "==9.2.6"
mkdocs-markdownextradata-plugin = "==0.2.5"

[requires]
python_version = "3.7"
python_version = "3.8"
460 changes: 429 additions & 31 deletions Pipfile.lock

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions docs/examples/nats.md

This file was deleted.

16 changes: 8 additions & 8 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ We have provided a command line tool to generate the scaffolding for the code of

### Command line flags

| Flag | Type | Required | Description |
|------------|--------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -name | string | Yes | Name of the module, use camel-case when needed. Only alphanumerical characters are allowed (leading character must be a letter). |
| -image | string | Yes | Fully-qualified name of the Docker image to be used by the module (i.e. 'docker.io/org/project:tag') |
| -title | string | No | A variant of the name supporting mixed casing (i.e. 'MongoDB'). Only alphanumerical characters are allowed (leading character must be a letter). |
| -as-module | bool | No | If set, the module will be generated as a Go module, under the modules directory. Otherwise, it will be generated as a subdirectory of the examples directory. |
| Flag | Short | Type | Required | Description |
|---------|-------|--------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| --name | -n | string | Yes | Name of the module, use camel-case when needed. Only alphanumerical characters are allowed (leading character must be a letter). |
| --image | -i | string | Yes | Fully-qualified name of the Docker image to be used by the module (i.e. 'docker.io/org/project:tag') |
| --title | -t | string | No | A variant of the name supporting mixed casing (i.e. 'MongoDB'). Only alphanumerical characters are allowed (leading character must be a letter). |


### What is this tool not doing?

Expand All @@ -45,13 +45,13 @@ We have provided a command line tool to generate the scaffolding for the code of
From the [`modulegen` directory]({{repo_url}}/tree/main/modulegen), please run:

```shell
go run . --name ${NAME_OF_YOUR_MODULE} --image "${REGISTRY}/${MODULE}:${TAG}" --title ${TITLE_OF_YOUR_MODULE}
go run . new example --name ${NAME_OF_YOUR_MODULE} --image "${REGISTRY}/${MODULE}:${TAG}" --title ${TITLE_OF_YOUR_MODULE}
```

or for creating a Go module:

```shell
go run . --name ${NAME_OF_YOUR_MODULE} --image "${REGISTRY}/${MODULE}:${TAG}" --title ${TITLE_OF_YOUR_MODULE} --as-module
go run . new module --name ${NAME_OF_YOUR_MODULE} --image "${REGISTRY}/${MODULE}:${TAG}" --title ${TITLE_OF_YOUR_MODULE}
```

### Adding types and methods to the module
Expand Down
89 changes: 89 additions & 0 deletions docs/modules/nats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# NATS

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 NATS.

## Adding this module to your project dependencies

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

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

## Usage example

<!--codeinclude-->
[Creating a NATS container](../../modules/nats/nats_test.go) inside_block:createNATSContainer
<!--/codeinclude-->

## Module reference

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

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

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

#### Image

If you need to set a different NATS Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for NATS. E.g. `testcontainers.WithImage("nats:2.9")`.

#### Wait Strategies

If you need to set a different wait strategy for NATS, you can use `testcontainers.WithWaitStrategy` with a valid wait strategy
for NATS.

!!!info
The default deadline for the wait strategy is 60 seconds.

At the same time, it's possible to set a wait strategy and a custom deadline with `testcontainers.WithWaitStrategyAndDeadline`.

#### Docker type modifiers

If you need an advanced configuration for NATS, you can leverage the following Docker type modifiers:

- `testcontainers.WithConfigModifier`
- `testcontainers.WithHostConfigModifier`
- `testcontainers.WithEndpointSettingsModifier`

Please read the [Create containers: Advanced Settings](../features/creating_container.md#advanced-settings) documentation for more information.

#### Set username and password

If you need to set different credentials, you can use `WithUsername` and `WithPassword`
options. By default, the username, the password are not set.

<!--codeinclude-->
[Define NATS container with credentials](../../modules/nats/nats_test.go) inside_block:withCredentials
<!--/codeinclude-->

To establish the connection with the NATS container:

<!--codeinclude-->
[Connect using the credentials](../../modules/nats/nats_test.go) inside_block:connectWithCredentials
<!--/codeinclude-->

### Container Methods

The NATS container exposes the following methods:

#### ConnectionString

This method returns the connection string to connect to the NATS container, using the default `4222` port.
It's possible to pass extra parameters to the connection string, in a variadic way.

<!--codeinclude-->
[Get connection string](../../modules/nats/nats_test.go) inside_block:connectionString
<!--/codeinclude-->
53 changes: 0 additions & 53 deletions examples/nats/nats.go

This file was deleted.

2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ nav:
- modules/mariadb.md
- modules/mongodb.md
- modules/mysql.md
- modules/nats.md
- modules/neo4j.md
- modules/postgres.md
- modules/pulsar.md
Expand All @@ -82,7 +83,6 @@ nav:
- examples/consul.md
- examples/datastore.md
- examples/firestore.md
- examples/nats.md
- examples/nginx.md
- examples/pubsub.md
- examples/spanner.md
Expand Down
25 changes: 25 additions & 0 deletions modulegen/cmd/modules/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package modules

import (
"github.com/spf13/cobra"

"github.com/testcontainers/testcontainers-go/modulegen/internal"
)

var newExampleCmd = &cobra.Command{
Use: "example",
Short: "Create a new Example",
Long: "Create a new Example",
RunE: func(cmd *cobra.Command, args []string) error {
return internal.Generate(tcModuleVar, false)
},
}

func init() {
newExampleCmd.Flags().StringVarP(&tcModuleVar.Name, nameFlag, "n", "", "Name of the example. Only alphabetical characters are allowed.")
newExampleCmd.Flags().StringVarP(&tcModuleVar.NameTitle, titleFlag, "t", "", "(Optional) Title of the example name, used to override the name in the case of mixed casing (Mongodb -> MongoDB). Use camel-case when needed. Only alphabetical characters are allowed.")
newExampleCmd.Flags().StringVarP(&tcModuleVar.Image, imageFlag, "i", "", "Fully-qualified name of the Docker image to be used by the example")

_ = newExampleCmd.MarkFlagRequired(imageFlag)
_ = newExampleCmd.MarkFlagRequired(nameFlag)
}
7 changes: 7 additions & 0 deletions modulegen/cmd/modules/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package modules

const (
imageFlag = "image"
nameFlag = "name"
titleFlag = "title"
)
Loading

0 comments on commit 3f43bae

Please sign in to comment.