kafkatest

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2019 License: MIT Imports: 8 Imported by: 0

README

The kafkatest package makes it a little easier to connect to a Kafka cluster for testing. It will automatically create topics and remove them at the end of the test.

Documentation

Overview

Package kafkatest provides a package intended for running tests that require a Kafka backend.

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = fmt.Errorf("kafka tests are disabled")

Functions

This section is empty.

Types

type Kafka

type Kafka struct {
	// contains filtered or unexported fields
}

Kafka represents a connection to a Kafka cluster.

func New

func New() (*Kafka, error)

New connects to a Kafka instance and returns a Kafka instance that uses it.

The following environment variables can be used to configure the connection parameters:

  • $KAFKA_DISABLE A boolean as parsed by strconv.ParseBool. If this is true, New will return ErrDisabled.

  • $KAFKA_ADDRS A comma-separate list of Kafka broker addresses in host:port form. If this is empty, localhost:9092 will be used. The list of address can be discovered by calling Client.Addrs.

  • $KAFKA_USERNAME, $KAFKA_PASWORD The username and password to use for SASL authentication. When $KAFKA_USERNAME is non-empty, SASL will be enabled.

  • $KAFKA_USE_TLS A boolean as parsed by strconv.ParseBool. If this is true, a secure TLS connection will be used.

  • $KAFKA_TIMEOUT The maximum duration to wait when trying to connect to Kakfa. Defaults to "30s".

The returned Kafka instance must be closed after use.

func (*Kafka) Addrs

func (k *Kafka) Addrs() []string

Addrs returns the configured Kakfa broker addresses.

func (*Kafka) Close

func (k *Kafka) Close() error

Close closes the client connection and removes any topics created by Topic. This method may be called more than once.

func (*Kafka) Config

func (k *Kafka) Config() *sarama.Config

Config returns a sarama configuration that will use connection parameters defined in the environment variables described in New.

func (*Kafka) InitConfig

func (k *Kafka) InitConfig(cfg *sarama.Config)

InitConfig is similar to Config, except that instead of returning a new configuration, it configures an existing one.

func (*Kafka) NewTopic

func (k *Kafka) NewTopic() string

NewTopic creates a new Kafka topic with a random name and single partition. It returns the topic's name. The topic will be deleted when c.Close is called.

NewTopic panics if the topic cannot be created.

Jump to

Keyboard shortcuts

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