https://github.com/kernle32dll/testcontainers-go-canned
A collection of templates for testcontainers-go.
https://github.com/kernle32dll/testcontainers-go-canned
go kafka testing
Last synced: over 1 year ago
JSON representation
A collection of templates for testcontainers-go.
- Host: GitHub
- URL: https://github.com/kernle32dll/testcontainers-go-canned
- Owner: kernle32dll
- License: mit
- Created: 2022-11-22T18:57:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-22T23:25:37.000Z (over 3 years ago)
- Last Synced: 2024-06-20T05:08:19.625Z (about 2 years ago)
- Topics: go, kafka, testing
- Language: Go
- Homepage:
- Size: 53.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](http://godoc.org/github.com/kernle32dll/testcontainers-go-canned)
[](https://goreportcard.com/report/github.com/kernle32dll/testcontainers-go-canned)
[](https://codecov.io/gh/kernle32dll/testcontainers-go-canned)
# testcontainers-go-canned
testcontainers-go-canned is a collection templates for
[testcontainers-go](https://github.com/testcontainers/testcontainers-go).
Download:
```
go get github.com/kernle32dll/testcontainers-go-canned@latest
```
Detailed documentation can be found on [GoDoc](https://godoc.org/github.com/kernle32dll/testcontainers-go-canned).
## 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...
```go
import "github.com/kernle32dll/testcontainers-go-canned/kafkatest"
[...]
kafkaCluster, err := kafkatest.NewKafkaCluster(ctx)
```
...and if done, call...
```go
kafkaCluster.StopCluster(ctx)
```
For some inspiration, look at the [cluster_test.go](./kafkatest/cluster_test.go) file, which actually tests
integration with [franz-go](https://github.com/twmb/franz-go).
#### Configuration
There are many `kafkatest.With[...]` option functions, you can use for vararg configuration of the cluster. E.g.:
```go
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](https://github.com/twmb/franz-go)):
```go
seed, err := kafkaCluster.GetKafkaHostAndPort(context.Background())
[...]
client, err := kgo.NewClient(
kgo.SeedBrokers(seed),
kgo.DialTLSConfig(kafkaCluster.ClientTLSConfig()),
)
```