testcontainers-go-canned

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2022 License: MIT

README

test GoDoc Go Report Card codecov

testcontainers-go-canned

testcontainers-go-canned is a collection templates for testcontainers-go.

Download:

go get github.com/kernle32dll/testcontainers-go-canned@latest

Detailed documentation can be found on GoDoc.

Compatibility

testcontainers-go-canned is automatically tested against the following:

  • Go 1.17.X, 1.18.X and 1.19.X

Getting started

Kafka

Simply initialize a new cluster via...

import "github.com/kernle32dll/testcontainers-go-canned/kafkatest"

[...]

kafkaCluster, err := kafkatest.NewKafkaCluster(ctx)

...and if done, call...

kafkaCluster.StopCluster(ctx)

For some inspiration, look at the cluster_test.go file, which actually tests integration with franz-go.

Configuration

There are many kafkatest.With[...] option functions, you can use for vararg configuration of the cluster. E.g.:

kafkaCluster, err := kafkatest.NewKafkaCluster(
    ctx,
    kafkatest.WithTLS(true),
)
TLS

Take special note of the kafkatest.WithTLS(true) option, which configures the cluster for full TLS. You can then use kafkaCluster.ClientTLSConfig() function to receive an tls.Config, you can plug into your kafka client like so for example (kgo is franz-go):

seed, err := kafkaCluster.GetKafkaHostAndPort(context.Background())
[...]

client, err := kgo.NewClient(
    kgo.SeedBrokers(seed),
    kgo.DialTLSConfig(kafkaCluster.ClientTLSConfig()),
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL