-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/exit-code-sugar
- Loading branch information
Showing
17 changed files
with
745 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ src/pip-delete-this-directory.txt | |
.DS_Store | ||
|
||
TEST-*.xml | ||
|
||
**/go.work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# InfluxDB | ||
|
||
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 | ||
|
||
A testcontainers module for InfluxDB. This module supports v1.x of InfluxDB. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the InfluxDB module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/influxdb | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating an InfluxDB container](../../modules/influxdb/examples_test.go) inside_block:runInfluxContainer | ||
<!--/codeinclude--> | ||
|
||
## Module Reference | ||
|
||
The InfluxDB module exposes one entrypoint function to create the container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) {} | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the container, you can pass options in a variadic way to configure it. | ||
|
||
!!!tip | ||
|
||
You can find configuration information for the InfluxDB image on [Docker Hub](https://hub.docker.com/_/influxdb) and a list of possible | ||
environment variables on [InfluxDB documentation](https://docs.influxdata.com/influxdb/v1/administration/config/). | ||
|
||
#### Image | ||
|
||
To use a different Docker image, you can use the `testcontainers.WithImage` option to specify the | ||
image, E.g. `testcontainers.WithImage("influxdb:1.8.0")`. By default, the 1.8.10 image is used. Note that | ||
`influxdb:latest` will get you a version 2 image which is not supported by this module. | ||
|
||
|
||
{% include "../features/common_functional_options.md" %} | ||
|
||
#### Set username, password and database name | ||
|
||
By default, authentication is disabled and no credentials are needed to use the Influx API against the test container. | ||
If you want to test with credentials, include the appropriate environment variables to do so. | ||
|
||
#### Init Scripts | ||
|
||
While the InfluxDB image will obey the `/docker-entrypoint-initdb.d` directory as is common, that directory does not | ||
exist in the default image. Instead, you can use the `WithInitDb` option to pass a directory which will be copied to | ||
when the container starts. Any `*.sh` or `*.iql` files in the directory will be processed by the image upon startup. | ||
When executing these scripts, the `init-influxdb.sh` script in the image will start the InfluxDB server, run the | ||
scripts, stop the server, and restart the server. This makes it tricky to detect the readiness of the container. | ||
This module looks for that and adds some extra tests for readiness, but these could be fragile. | ||
|
||
!!!important | ||
The `WithInitDb` option receives a path to the parent directory of one named `docker-entrypoint-initdb.d`. This is | ||
because the `docker-entrypoint-initdb.d` directory is not present in the image. | ||
|
||
#### Custom configuration | ||
|
||
If you need to set a custom configuration, you can use `WithConfigFile` option to pass the path to a custom configuration file. | ||
|
||
### Container Methods | ||
|
||
#### ConnectionUrl | ||
|
||
This function is a simple helper to return a URL to the container, using the default `8086` port. | ||
|
||
<!--codeinclude--> | ||
[ConnectionUrl](../../modules/influxdb/influxdb_test.go) inside_block:influxConnectionUrl | ||
<!--/codeinclude--> | ||
|
||
Please check the existence of two methods: `ConnectionUrl` and `MustConnectionUrl`. The latter is used to avoid the need to handle errors, | ||
while the former is used to return the URL and the error. `MustConnectionUrl` will panic if an error occurs. | ||
|
||
!!!info | ||
The `ConnectionUrl` and `MustConnectionUrl` methods only support HTTP connections at the moment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../../commons-test.mk | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) test-influxdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package influxdb_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/modules/influxdb" | ||
) | ||
|
||
func ExampleRunContainer() { | ||
// runInfluxContainer { | ||
ctx := context.Background() | ||
|
||
influxdbContainer, err := influxdb.RunContainer( | ||
ctx, testcontainers.WithImage("influxdb:1.8.10"), | ||
influxdb.WithDatabase("influx"), | ||
influxdb.WithUsername("root"), | ||
influxdb.WithPassword("password"), | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to start container: %s", err) | ||
} | ||
|
||
// Clean up the container | ||
defer func() { | ||
if err := influxdbContainer.Terminate(ctx); err != nil { | ||
log.Fatalf("failed to terminate container: %s", err) | ||
} | ||
}() | ||
// } | ||
|
||
state, err := influxdbContainer.State(ctx) | ||
if err != nil { | ||
log.Fatalf("failed to get container state: %s", err) // nolint:gocritic | ||
} | ||
|
||
fmt.Println(state.Running) | ||
|
||
// Output: | ||
// true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module github.com/testcontainers/testcontainers-go/modules/influxdb | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c | ||
github.com/stretchr/testify v1.9.0 | ||
github.com/testcontainers/testcontainers-go v0.29.1 | ||
) | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/Microsoft/hcsshim v0.11.4 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||
github.com/containerd/containerd v1.7.12 // indirect | ||
github.com/containerd/log v0.1.0 // indirect | ||
github.com/cpuguy83/dockercfg v0.3.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/distribution/reference v0.5.0 // indirect | ||
github.com/docker/docker v25.0.5+incompatible // indirect | ||
github.com/docker/go-connections v0.5.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/felixge/httpsnoop v1.0.3 // indirect | ||
github.com/go-logr/logr v1.2.4 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-ole/go-ole v1.2.6 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/klauspost/compress v1.16.0 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/moby/patternmatcher v0.6.0 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/sys/user v0.1.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect | ||
github.com/shirou/gopsutil/v3 v3.23.12 // indirect | ||
github.com/shoenig/go-m1cpu v0.1.6 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/tklauser/go-sysconf v0.3.12 // indirect | ||
github.com/tklauser/numcpus v0.6.1 // indirect | ||
github.com/yusufpapurcu/wmi v1.2.3 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect | ||
go.opentelemetry.io/otel v1.19.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.19.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.19.0 // indirect | ||
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect | ||
golang.org/x/mod v0.16.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/tools v0.13.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect | ||
google.golang.org/grpc v1.58.3 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) | ||
|
||
replace github.com/testcontainers/testcontainers-go => ../.. |
Oops, something went wrong.