Documentation
¶
Index ¶
- func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption
- func WithDatabase(database string) testcontainers.CustomizeRequestOption
- func WithInitDb(srcPath string) testcontainers.CustomizeRequestOption
- func WithPassword(password string) testcontainers.CustomizeRequestOption
- func WithUsername(username string) testcontainers.CustomizeRequestOption
- func WithV2(org, bucket string) testcontainers.CustomizeRequestOption
- func WithV2AdminToken(token string) testcontainers.CustomizeRequestOption
- func WithV2Auth(org, bucket, username, password string) testcontainers.CustomizeRequestOption
- func WithV2Retention(retention time.Duration) testcontainers.CustomizeRequestOption
- func WithV2SecretsAdminToken(tokenFile string) testcontainers.CustomizeRequestOption
- func WithV2SecretsAuth(org, bucket, usernameFile, passwordFile string) testcontainers.CustomizeRequestOption
- type InfluxDbContainer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithConfigFile ¶
func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption
func WithDatabase ¶
func WithDatabase(database string) testcontainers.CustomizeRequestOption
func WithInitDb ¶
func WithInitDb(srcPath string) testcontainers.CustomizeRequestOption
WithInitDb returns a request customizer that initialises the database using the file `docker-entrypoint-initdb.d` located in `srcPath` directory.
func WithPassword ¶
func WithPassword(password string) testcontainers.CustomizeRequestOption
func WithUsername ¶
func WithUsername(username string) testcontainers.CustomizeRequestOption
func WithV2 ¶ added in v0.37.0
func WithV2(org, bucket string) testcontainers.CustomizeRequestOption
WithV2 configures the influxdb container to be compatible with InfluxDB v2
func WithV2AdminToken ¶ added in v0.37.0
func WithV2AdminToken(token string) testcontainers.CustomizeRequestOption
WithV2AdminToken sets the admin token for the influxdb container
func WithV2Auth ¶ added in v0.37.0
func WithV2Auth(org, bucket, username, password string) testcontainers.CustomizeRequestOption
WithV2Auth configures the influxdb container to be compatible with InfluxDB v2 and sets the username and password for the initial user.
func WithV2Retention ¶ added in v0.37.0
func WithV2Retention(retention time.Duration) testcontainers.CustomizeRequestOption
WithV2Retention configures the default bucket's retention
func WithV2SecretsAdminToken ¶ added in v0.37.0
func WithV2SecretsAdminToken(tokenFile string) testcontainers.CustomizeRequestOption
WithV2SecretsAdminToken sets the admin token for the influxdb container using a file
func WithV2SecretsAuth ¶ added in v0.37.0
func WithV2SecretsAuth(org, bucket, usernameFile, passwordFile string) testcontainers.CustomizeRequestOption
WithV2SecretsAuth configures the container to be compatible with InfluxDB v2 and sets the username and password file path
Types ¶
type InfluxDbContainer ¶
type InfluxDbContainer struct {
testcontainers.Container
}
InfluxDbContainer represents the InfluxDB container type used in the module
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error)
Run creates an instance of the InfluxDB container type
Example ¶
// runInfluxContainer {
ctx := context.Background()
influxdbContainer, err := influxdb.Run(ctx,
"influxdb:1.8.10",
influxdb.WithDatabase("influx"),
influxdb.WithUsername("root"),
influxdb.WithPassword("password"),
)
defer func() {
if err := testcontainers.TerminateContainer(influxdbContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := influxdbContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
Output: true
Example (V2) ¶
// runInfluxV2Container {
ctx := context.Background()
username := "username"
password := "password"
org := "org"
bucket := "bucket"
token := "influxdbv2token"
influxdbContainer, err := influxdb.Run(ctx, "influxdb:2.7.11",
influxdb.WithV2Auth(org, bucket, username, password), // Set the username and password
influxdb.WithV2AdminToken(token), // Set the admin token
)
defer func() {
if err := testcontainers.TerminateContainer(influxdbContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := influxdbContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
// Query the InfluxDB API to verify the setup
url, err := influxdbContainer.ConnectionUrl(ctx)
if err != nil {
log.Printf("failed to get host: %s", err)
return
}
// Initialize a new InfluxDB client
client := influxclient2.NewClientWithOptions(url, token, influxclient2.DefaultOptions())
defer client.Close()
// Get the bucket
influxBucket, err := client.BucketsAPI().FindBucketByName(ctx, bucket)
if err != nil {
log.Printf("failed to get bucket: %s", err)
return
}
fmt.Println(influxBucket.Name)
Output: true bucket
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the InfluxDB container type
func (*InfluxDbContainer) ConnectionUrl ¶
func (c *InfluxDbContainer) ConnectionUrl(ctx context.Context) (string, error)
func (*InfluxDbContainer) MustConnectionUrl ¶
func (c *InfluxDbContainer) MustConnectionUrl(ctx context.Context) string